Software Architects have been involving lot of debates about different approaches and architectures. Some of the examples are ORM Vs Store Procedures, REST Vs SOAP, etc. There is a debate happening inside the Microsoft community about ASP.net web form Vs ASP.net MVC. Many people thinking that ASP.net MVC will be replace webforms at least eventually and others are thinking that ASP.net MVC will not be replace webforms. Will ASP.net MVC replace webforms?. ASP.net MVC is an alternative approach to webforms rather than a replacement. It will not replace webforms and webforms will not replace ASP.NET MVC. The fact is that ASP.NET MVC and webforms will co-exist and that ASP.NET MVC is not a replacement for webforms. If you prefer ASP.net MVC use it and you feel webform is more comfortable, you can use it. . Both approaches are just choices and different approaches and choices are good things. Different choices are available for other platforms especially in the Java platform.
Problems with ASP.net Web Form
The ASP.net MVC way
The ASP.NET MVC simplifies the complex parts of ASP.net Web Forms without any compromise of the power and flexibility of ASP.NET platform. ASP.net MVC implements Model-View-Controller UI pattern for web application development that lets you allows to develop applications in a loosely couples manner. MVC pattern is separating the application in three parts- Model, View and Controller. A view is responsible for rendering the user interface (UI) of the application and it is nothing more than html templates that filled with application’s data passed by the controller. The Model implements the logic for the application’s data and it represents the business objects of the application that using the View for rendering user interface. Controllers are handles and responds to user input and interaction. The web request will be handled by the controller, and the controller will decide which model objects to use and which view objects to render. The MVC model replaces the Web Form events with the controller actions. The main advantages of the MVC models are clear separation of concerns, unit testing facility, and more control over the URLs and HTML. The MVC model does not use Viewstate, Postbacks, Server controls, and server-based forms that enable full control over the application and html rendered by the Views. MVC model is using Representational state transfer (REST) based URLs instead of file-name extensions used by the Web Form model so that we can make search engine optimization (SEO) URLs published by the application.
The below code shows the implementation of MVC application.
In this sample, I have used extension methods to the HtmlHelper class to display ordered list of information.
Advantages of MVC Model
- Enable clean separation of concerns (SoC) .
- Enable full control over the rendered HTML.
- Enable Test Driven Development (TDD) (built with TDD in mind).
- SEO and REST friendly URL.
- Support third-party view engines such as NVelocity, Brail, NHaml.
- No ViewState and PostBack events.
- Follows the stateless nature of web.
- Extensible and Pluggable framework.
- Ideal platform for Web 2.0 applications.
Advantages of Web Form Model
- Provides RAD development.
- Easy development model for heavy data-driven LOB applications.
- Provides rich controls.
- Familiar model for windows form developers.
Which is the best approach?
The choice would be vary on different people. If you want more control over the HTML or you want Test Driven Development (TDD), or you care about web standards, accessibility, or you want to build SEO based URLs, you can choose MVC model. If you want rich controls and state oriented event-driven web development, you can choose Web Forms model. If you feel more comfortable with MVC, choose that model and you feel Web Form model is more comfortable, choose that model. Both are just choices. If you start your career with ASP.net Web Forms and do not have full knowledge of Web, it will be very difficult moving to MVC model.
One thought on “ASP.net MVC Vs ASP.net Web Form”
I started building my first .net web app with Web Forms. I quickly ran back to the client and said, listen. I know a lot about front end design and database stuff, the way I am going about this is wrong. Give me some time to learn MVC and I will be ab;e to deliver much more customizable App. That client paid for my training and I lowballed the quote a bit to compensate for the extra time spent. I am so glad I chose MVC. At the same time, there are many developers in the banking or Real Estate Industry that Web Forms type development is very useful, especially when we are talking about data intense grids and less control over customization in exchange for rapid development time. Nice article.