ASP.NET MVC and Codebehind Files

I’ll throw my 2 cents in here:  I will agree that by default this shouldn’t be needed.  I’d rather add the ViewData model type to the aspx page itself.

What do I mean?

public partial class Employee : ViewUserControl<Core.Domain.Employee>

Quite honestly I think that is about all I use the code behind files for in the views.   There were some cases I would handle the page load event and bind to a Repeater, but those were typically not the approach I would use (I opted for a  HtmlHelper, ie. Html.Grid or Html.Repeater instead).

So, I like the idea of defining the ViewData<T> type in the actually aspx and then not require this additional code behind file.

Personally, I’d keep both available, making Tim Barcz’s technique the default


2 thoughts on “ASP.NET MVC and Codebehind Files

  1. I think that warrants a new View Engine (a-la NVelocity).

    People will definitely use a codebehind and if you aren’t going to use codebehind, maybe you are using the wrong View Engine. Maybe you need something lighter.

  2. Good point. I know that NVelocity worked quite well for me in the little bit of Monorail I was doing.

    The brail engine sounds good to me – I haven’t examined the mvccontrib available view engines too much, but eventually I will.

    (I do like the Html helpers, so I’d probably stick to a view engine that supported that)

    I did a search and here are some available:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s