Tuesday, December 16, 2008

ASP.NET Development: MVC vs. Web Forms

ASP.NET Web Forms

ASP.NET Web forms is a mature technology that runs many large scale websites and is the traditional style of ASP.NET web development. Starting in the .NET framework version 1.0 it is the first technology where Microsoft made an effort to make web development very robust and much more simple. The web forms declarative syntax plus the event driven model allows you to take full advantage of visual designers by drag and dropping the controls onto ASP.NET pages and then writing code against them, much like Windows style development. This makes web forms development very enticing for a wide range of developers on both Windows and other platforms, where drag and drop development via visual designers is common and also provides a separation of web content and web page GUI logic. The key features of web forms include:

* Mature technology
* Rich toolset & controls
* Event driven model
* Easy state management
* Abstracts HTTP
* Feels like Windows development


ASP.NET MVC

MVC (Model View Controller) isn’t a Microsoft technology (and, it’s not even new). , it’s a pattern for web page creation that’s been around for some time now in other frameworks and just recently implemented in ASP.NET. As a developer using MVC you can get a ‘closer to the metal’ experience and finely tuned control of the HTML output, which will be exactly as you define it. Whereas web forms renders output based on your selections of controls and code, MVC is primarily your code with some HTML interspersed, so you get control of each pixel that’s rendered.

The three features of MVC, the model, view and controller are described here…

* The Model can be thought of as the data. This is going to be your fat layer, with all the goodies in it.
* The View is the UI representation of the Model. The view will render the model along with HTML, JavaScript and other page elements.
* The Controller chooses the view to be rendered and responds to user input. The view also manipulates the model, as needed, so the controller is the component that ties the Model and View together. The controller will be the most lightweight code-wise of the three.

As you can see, the MVC approach requires you to work with three objects rather than just one object (the page object) as web forms does. This object trio does give you some advantages over the traditional model:

* It’s testable, you can unit test easily
* Clear separation of concerns
* Control your output exactly
* Map URLs logically or dynamically
* Supports many web forms features (auth, caching, etc…)
* More geeky, higher coolness factor

Read More...

No comments: