Differences between Asp.Net Web Forms and Asp.Net MVC


Even though both Asp.Net Web Forms and Asp.Net MVC built on core Asp.Net APIs and .Net Framework, there are some differences between them. In this article we discuss about those differences in detail. Below table lists the differences between Asp.net Web Forms and Asp.Net MVC.

               Asp.Net Web Forms

                    Asp.Net MVC

Pages handles requests

Controllers handles requests

Views tightly couple to logic

Views and logic kept separate

View state used for state management

No automatic state management

Server Controls

HTML helper classes

Master pages

Layouts

Web User controls

Partial views

 

Pages Vs Controllers

In Asp.Net Web Forms applications pages (extension .aspx) handles incoming requests whereas in Asp.Net MVC Controller (extension .cs) handles incoming requests. Controllers are nothing but.Net classes but name should be ended with Controller to differentiate them from normal classes. For example DefaultController.cs will be the valid Asp.Net MVC Controller.


State Management

View State maintains state at client side. Asp.Net Web Forms has View state to maintain the state whereas Asp.Net MVC ditches the View State and become the completely stateless. You can maintain the state in Asp.Net MVC by using Session, which means we can achieve the state management facility in Asp.Net MVC by using session at server side. For state management techniques in Asp.Net Web Forms visit /post/State-Management-using-QueryString-Cookies-ViewState-Session-and-Application-in-ASPNET-2605 .


Server Controllers Vs HTML helper Classes

In Asp.Net Web Forms data binds using Asp.Net Server Side controllers in .aspx page. In Asp.net MVC HTML helper classes helps us to bind the data in .cshtml UI (In Asp.Net MVC .cshtml screens used to display the data in UI). As we don’t have View State in Asp.Net MVC, we have only HTML controls to display the data. For HTML helper classes /post/html-and-url-helper-methods-in-asp-net-mvc .


Master Pages Vs Layouts

To maintain the common layout in applications we have Master pages (.master) in Asp.Net Web Forms whereas Layouts (.cshtml) in Asp.Net MVC. Both Maste pages & Layouts behaves same to provide the consistent look and feel across the applications. For Asp.Net Master Pages visit /post/Master-Page-and-Content-Pages-In-ASPNET  & for Asp.Net MVC Layouts visit /post/layouts-in-asp-net-mvc .


Web User Controls Vs Partial Views

To re-use the common functionality in several places across the application we have Web User Controls (.ascx) in Asp.Net Web Forms. Same we can achieve by using Partial Views (.cshtml) in Asp.Net MVC. For more info on Asp.Net Web user Controls visit /post/4MicrosoftSolutionsWeb-User-Conrols-in-ASPNET & for Asp.Net MVC Partial Views visit /post/partial-views-in-asp-net-mvc.