David Williams

Who's sruffy looking?

  Home  |   Contact  |   Syndication    |   Login
  19 Posts | 0 Stories | 16 Comments | 0 Trackbacks

News



Twitter












Archives

Post Categories

Microsoft Development

Thursday, October 14, 2010 #

At a high level, this is how I understand the different MVC tiers:

  • Model: Data libraries such as entities, Linq to SQL classes, or any other data library.
  • View: The .aspx/.ascx pages.  The classic ASP style code goes here.  I have heard this layer referred to as a ‘report’ where you have as little logic as possible, and only that related to the display of the page. 
  • Controller:  If you are coming from ‘standard’ ASP.Net and are new to MVC, You could say the controller is what replaces the code behind.  However the controller is very different.  Think of a controller as code that packages data to send to View.  It has no events, no viewstate, but a series of actions or methods that return data to the View.
  • “View Model”:  Think of a ViewModel as having only the data that is needed by the View.  Typically the controller takes data from (for example) one or more Models, and places it in the ViewModel.  Not all data from the Model makes it into the view, and the controller can add additional info not in the Model. 

Someone asked me the other day, between Standard ASP.Net and ASP.Net MVC, which do I prefer and why.  Although I have long been an ASP.Net developer, I have to say that I easily would choose MVC over standard ASP.net any day (and twice on Sunday).   I feel this for the following reasons:

  • Separation of interests: The three sections of MVC are logically separated: Model(Data), View(.aspx page), Controller (Code that feeds data to view). 
  • NO VIEWSTATE:  If you are new to MVC, you think this is a bad thing, but it is actually very, very good.
  • Performance: Because there is no viewstate, there is no decoding/encoding of viewstate, no unneeded data passed back and forth to the browser.
  • MVC is more AJAX/JavaScript friendly.  For example:  No more funky control names like ‘ctl00_pagebody_ucSetupList_gvSetups_ctl02_hlSetupName’.
  • Easier to test.  Separation of interests allows you to test the controller methods directly.
  • No events.  Like ViewState, if you are new to MVC, you think this is bad.  Actually this too is very very good.
  • Did I say NO VIEWSTATE?  Yes, but it bears repeating.

Personally I am in love with MVC and no longer enjoy working on any of my legacy ‘standard’ ASP.Net sites.