Saturday, August 10, 2013

ASP.NET MVC: Why Should I Move From Web Forms

Having used ASP.NET MVC quite extensively, I can tell you that ASP.NET Web Forms is quite good for prototyping. However, when you get to building Internet applications, ASP.NET MVC provides you with a lot of control over the markup of your application. Sure, it is more effort when you want to build the user interface and at times I did think that something I was building would have taken lesser time to build with ASP.NET Web Forms - quite possibly one of the reasons why Microsoft announced one ASP.NET, a statement that you can mix ASP.NET MVC and ASP.NET WebForms code within the same project.

ASP.NET MVC provides scaffolding (through code-generation) to reduce the effort involved in creating ASP.NET MVC user interfaces. Well, it is supposed to - it is still buggy when dealing with relationships between entities but when you have unrelated entities it works perfectly. This is most likely something that would be fixed in the next release or in one of the updates to Visual Studio. You can also take advantage of a wide variety of HTML/CSS/Javascript user interface components that you can use with ASP.NET MVC so if you need to build a user interface coherent with one built using PHP, Python, or Ruby, you don't have to create subclasses of the Label, TextBox, GridView, and ListView controls or add 'hacky' (seriously, doing a find-and-replace on the generated markup is an unnecessary CPU overhead) event handlers to alter the markup. The additional effort that you put into create the MVC views does pay off because with model binding, ASP.NET MVC can perform validation with nothing more than annotations (attributes) on your model. HTML 5 control rendering is also possible through adding attributes to your model. Sure, purists would argue that you shouldn't be adding attributes on your model to affect the presentation of your application but all you are doing is further describing the type of data being stored using the model and the view simply adapts (if you want it to).

I would also like to mention that when you do see performance benchmarks comparing a Hello World page in ASP.NET MVC, make sure that the benchmarks compared the ASP.NET MVC framework to another MVC framework - there are some comparisons of a Handler-like (ASHX) processing mechanism on other platforms to a Hello World on ASP.NET MVC and that just isn't fair - as soon as you use MVC, you've got routing and that adds additional processing to the application so you are bound to get lower performance scores when compared to a non-MVC framework. 

No comments: