Difference Between ASP.NET WebForms and ASP.NET MVC




One of the frequently asked questions about ASP.NET MVC is that how is different from ASP.NET WebForms. Is ASP.NET MVC a replacement for WebForms.

The answer is No. ASP.NET MVC, is not a replacement for WebForms. Both ASP.NET MVC and ASP.NET WebForms are built on top of the Core ASP.NET Framework. In fact a lot of features we use in ASP.NET such as Roles, Membership, Authentication and a lot of namespaces, classes and interfaces can be used in an ASP.NET MVC application

Here are some points that I wrote in an article for www.dotnetcurry.com that differentiate ASP.NET WebForms from ASP.NET MVC:

ASP.NET WebForms

ASP.NET MVC

Uses the ‘Page Controller’ pattern. Each page has a code-behind class that acts as a controller and is responsible for rendering the layout.Uses the ‘Front Controller’ pattern. There is a single central controller for all pages to process web application requests and facilitates a rich routing architecture
Uses an architecture that combines the Controller (code behind) and the View (.aspx). Thus the Controller has a dependency on the View. Due to this, testing and maintainability becomes an issue.ASP.NET MVC enforces a "separation of concerns". The Model does not know anything about the View. The View does not know there’s a Controller. This makes MVC applications easier to test and maintain
The View is called before the Controller.Controller renders View based on actions as a result of the User Interactions on the UI.
At its core, you ‘cannot’ test your controller without instantiating a View. There are ways to get around it using tools.At its core, ASP.NET MVC was designed to make test-driven development easier. You ‘can’ test your Controller without instantiating a View and carry out unit-tests without having to run the controllers in an ASP.NET process.
WebForms manage state by using view state and server-based controls.ASP.NET MVC does not maintain state information by using view state
WebForms supports an event-driven programming style that is like Windows applications and is abstracted from the user. The State management is made transparent by using sessions, viewstate etc. In the process, the HTML output is not clean making it difficult to manage later. The ViewState also increases your page size.In ASP.NET MVC, the output is clean and you have full control over the rendered HTML. The orientation is towards building standard compliant pages and provides full control over the behavior of an application.
Deep understanding of HTML, CSS and JavaScript is not required to a large extent since the WebForm model abstracts a lot of these details and provides automatic plumbing. While abstracting details to provide ease of use, sometimes a solution is overcomplicated, than it needs to be.A thorough understanding of how HTML, CSS and JavaScript work together is required. The advantage is you can do a lot of jQuery and AJAX stuff in an efficient and simple manner than you would do in an ASP.NET application.
WebForms can drastically reduce time while building up intranet and internet applications that use a lot of controls (drag and drop model). Although this is true for development, a lot of time is spent later to code around limitations.You lose the 'drag and drop' quick model of building your web applications. The focus is on control over the application behavior and test-driven development. The model is extensible and you do not have to spend time working around limitations.
Relatively simple to learn and pickup. Works very well for developers who initially have trouble with the HTTP/HTML model and are coming from a similar WinForms oriented event model.There is a learning curve to understand the why, when and how of ASP.NET MVC.
Lesser amount of code is required to build webapps since a lot of components are integrated and provided out of the box. You can also use a lot of data controls provided out of the box that rely on ViewState.Since the application tasks are separated into different components, amount of code required is more. Since ASP.NET MVC does not use ViewState, you cannot use Data controls like GridView, Repeater.
Works very well for small teams where focus is on rapid application developmentWorks well for large projects where focus in on testability and maintainability

I hope devcurry.com viewers will find this table useful. The entire article can be read over here ASP.NET MVC - Some Frequently Asked Questions



Will you give this article a +1 ? Thanks in advance




About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

comments

8 Responses to "Difference Between ASP.NET WebForms and ASP.NET MVC"
  1. Anonymous said...
    May 20, 2010 at 5:21 AM

    excellent

  2. Hiran said...
    June 12, 2010 at 4:35 AM

    Hi it really helped me to learn the differences between those. Are there any good resources to learn ASP.NET MVC 2.0.

  3. Suprotim Agarwal said...
    June 12, 2010 at 6:25 AM

    Some ASP.NET MVC resources:

    ASP.NET MVC Free Training

    ASP.NET MVC Articles

  4. haris said...
    July 7, 2010 at 1:30 AM

    Hello Evey One,

    I am very new to ASP.NET MVC.
    Can you please tell me how to create TreeView Dynamically at runtime with user input in ASP.NET MVC.

    where User should able to create Root, Parent and child nodes.
    User should be able to Add , edit, delete Nodes.

    Please post code here or send me at this email. haris105@hotmail.com

    Thank you in adnavce.

  5. Shazad said...
    January 29, 2011 at 8:03 AM

    I haven't use ASP.net MVC. But have worked on ASP.net webforms and Classic ASP 3.0. What I understand from this article, ASP.net MVC is some what similar to ASP Classic. So why they are going backward as it has its cons.

  6. Bartek said...
    March 4, 2011 at 8:45 PM

    In my opinion, the question is becoming blurred with a lot of the cool features of MVC making their way into Webforms. ASP.NET 4.0 added URL Routing, reduced ViewState, and greater control of the HTML mark-up produced by many ASP.NET controls, now the next version of Webforms will incorporate many more MVC features into Webforms. http://bit.ly/dNhBd8

  7. Noushad said...
    August 24, 2011 at 8:46 AM

    Very clear

  8. Shreekanth Gaanji said...
    March 13, 2013 at 3:09 AM

    It was a lear explination and well explained.

 

Copyright © 2009-2014 All Rights Reserved for DevCurry.com by Suprotim Agarwal | Terms and Conditions