I’ve read a lot of posts and articles about why and when you should choose WebForms or the MVC framework to build your ASP.NET websites. They are all pretty good, but for some reason they forget or ignore the obvious third option - standard ASP.NET without the WebForm.
Let’s call standard ASP.NET without a WebForm for ZeroForm. Basically, the ZeroForm approach is to use ASP.NET like you always have but without a <form runat="server"> element. I consider the ZeroForm as an excellent compromise between WebForms and MVC.
Server- and user controls
There are some immediate drawbacks from regular ASP.NET WebForms by not using the <form runat="server"> tag. A lot of the regular server controls like the TextBox, DropDownList and all the validators will not work. Other controls like the Repeater, PlaceHolder, custom user controls and all HtmlControls like <div runat="server"> will work as normal. Where WebForms support all the controls and the MVC framework none, this can be considered a good compromise.
ViewState and HTML markup
By getting rid of the WebForm, you are now in (almost) complete control of your markup. No ViewState, WebResource.axd’s and embedded JavaScript are injected in your pages anymore. The only thing that remains out of our control is the rendered ID’s of HTML elements. If you nest server- or user controls you still cannot control that until the release of .NET 4.0. Again, a fair compromise.
Pretty URLs
The MVC framework has a very cool way of creating pretty URLs using the new routing engine in .NET 3.5 SP1. You can use the routing engine with your WebForms and ZeroForms, but it isn’t really as fluent as in a MVC application. But hang on; URL rewriting has always been possible in ASP.NET so you could get the same pretty URLs by using ZeroForms. It does take some extra work but people have been doing it for years using various libraries or their own implementations. This is not a compromise, but the notion of that it's possible on both frameworks.
Separation of concerns
The MVC framework is the champ in separating concerns in your web application. No question about it. A lot of articles explain this very well, so I will not go into details. What haven’t been well explained is that by using the ZeroForm you can also separate a whole lot. Keep your model (custom objects) separate from the code-behind and your .aspx’s and .ascx’s as dumb as possible by leaving the code-behind to deal with data using utility classes or helpers that can be tested. This is nothing near the separation the MVC framework offers, but it is a good compromise.
This post is not meant to bash either WebForms or the MVC framework, but to offer an alternate view for your consideration. I’m a huge fan of WebForms, ZeroForms and the MVC framework and I use them all for different types of projects respectively.
An example of a website using the ZeroForm approach is ifjernsyn.dk (in Danish).
...Full Article.
No comments:
Post a Comment
Post your comments here: