RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


ASP.NET MVC and Web Forms -- Shaping the Future of the Web : Page 2

Over the next few years, MVC will develop and catch up with Web Forms and will be a strong contender for developer's favorite.


Test Driven Development (TDD)

MVC is best suited for test driven development and well-matched where testing is a prime concern. This is where developer can write test cases ahead of the actual code and then run the test cases to verify the accuracy of the code written. The crux of the difference between Web Forms and MVC exists in this area. Web Forms development makes it very difficult to write automation test scripts because of the underline associated events. You need to browse through the application pages and generate all those events that require testing. However, in MVC we write Controller methods for every possible (GET/POST) request applicable in the application and that can be tested without browsing through the entire application manually. So even though the testing framework remains the same but because of event handlers for all the possible routing options, TDD is more suitable in MVC.

Visual Studio 2010 comes with a built in framework for Unit Testing your MVC application and unlike any other project, prompts for a Test project by default while creating a new MVC project. Any of the externally supported frameworks like nUnit or MbUnit can also be used for TDD development with MVC.

ViewState issues and control over HTML

As we know that HTTP is a stateless protocol. To maintain the state of controls between requests, ViewState is used. ASP.NET Web Form applications can get into various performance issues because of ViewState. ViewState Information travels with each request in the form of hidden controls and can quickly choke the server if either the number of controls using view state grows or number of users grows. Diagram 4 shows output of a typical ASP Web Form application and has View State related overheads.

Diagram 4: Typical HTML response of an ASP .NET Web Form page. 

Diagram 5 shows output of a typical MVC application and clearly, is neat and clean as it can get.

Diagram 5: Typical HTML response of an ASP .NET MVC page.

Web Forms abstract developers from a lot of insides of the web server request and response process. If you never had to deal with it then Web Forms is the way to go. In case you need more control over the HTML response generated, MVC is a better choice. The page life cycle of MVC application is completely different from Web Forms. While Web Forms are event driven, MVC has got the power of URL routing and posting form data. Appropriate use of these will substitute all dependency upon ViewState.

Learning Curve

If you are migrating from Web Forms School of thoughts then the learning curve for MVC may be slightly longer. MVC is not good or bad; it’s just different way of programming that requires a completely different mindset to develop applications. With MVC, you experience gain the good old flavor of the web; that is stateless activities, full control and more responsibility for everything.

Diagram 6: Request handling difference between Web Forms and MVC.

Incoming request in MVC is handled by the URL route and then selects the appropriate Controller to further handle the request. Basically there is no concept of page life cycle in MVC. This non event driven model makes it more fine grain and different from legacy ASP.NET Web Forms. There are lots of step by step tutorials available at http://www.asp.net/mvc.

Server Controls

Server Controls is assumed to be the power of ASP.NET Web Forms. It provides the required reusability and rapid application development. Web Forms supports an enormous marketplace of custom user controls, many of them are exceptionally refined and save huge amounts of work. On the other hand, a MVC View does not use the runat="server" tag. The life cycle of a MVC page is completely different from a traditional Web Form page. If at any stage you feel that you need to use runat=”server” tag or enable the ViewState, you may have to relook your design. ViewState and postbacks are against the MVC architecture. Having said, you may still reuse all the server controls that do not require post back and ViewState. MVC has got the power of URL routing and posting form data. Appropriate use of these will substitute all dependency upon Server Controls and ViewState. Also, there are extensions to ASP.NET MVC to help developer community to build rich user interface in ASP.NET MVC using the reusable controls. Here is one such link on the CodePlex


Search Engine Optimization

In MVC, the request is not a physical page on the server; it’s actually a method of the controller class. Web Forms assume a one to one mapping between request and a physical resource on the web server. “http://yoursite/Home/default.aspx” in Web forms assumes that there exists a page called default.aspx on the server. This limitation does not allow having search engine friendly names. On the other hand, MVC uses smart URL routing which allows better names for SEO purpose. For example, typical urls from WebForms are like http://server/Products.aspx?Category=123 which is not only easily hack-able but also not so human and search engine friendly (We really don’t know what Category 123 means). However, with MVC the typical url is http://server/Products/household which is easy to understand by humans as well as search engines.

If the application in consideration is an Internet application and requires good Search Engine Optimization (SEO) to keep up with competitors, then MVC can be considered. Because in that case the longer learning curve has a business value attached to it.


If you are an expert with ASP.NET Web Form programming model, it will take some time before you can be equally productive with MVC but once achieved it is worth the effort. Also, MVC is an alternate to ASP.NET Web Form development and not a replacement. Both these frameworks are going to stay in parallel and mature with time. While I am writing this, there is already discussion happening for the next version of ASP.NET MVC 3. Over the next few years, MVC will develop and catch up with Web forms and will be a strong contender for shaping the future of Web.





What You See Is What You Get


Test Driven Development


Don’t Repeat Yourself


Asynchronous JavaScript and XML


Uniform Resource Locator




Sanjeev is working as Technology Lead at Infosys Technologies Limited, India and part of Product Engineering Unit. Reach him by e-mail @ Sanjeev_Magoo@Infosys.com
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date