In this post I’ll share my experiences on choosing between ASP.NET WebForms and MVC for a project I recently began working on.
Microsoft has two frameworks available for web development ASP.NET WebForms and ASP.NET MVC. Both build off the ASP.NET Framework. While Web Forms continue to be improved (Web Forms: Reports of my death have been greatly exaggerated by Damien Edwards at MIX11), MVC currently has had a lot of fanfare with the release of MVC3 in January 2011 and the recent release of MVC3 Tools Update (Introducing MVC3 Tools Update by Phil Haack). With all the hype behind MVC and the ongoing support and improvements to Web Forms, which is the best solution for your upcoming project? Like the typical IT answer…. “It depends”.
First let’s take a brief look at what each has to offer (won’t go into to much detail — there is plenty of information on each of the two frameworks on the web and Vaibhav does an excellent job providing a detailed SWOT analysis Choosing between Web Forms and MVC).
Web Forms
- Control and event base programming model
- Controls encapsulate HTML, JS and CSS (you can see this when you drag and drop controls on a form using the designer)
- Rich UI controls included – datagrids, charts, AJAX controls
- SharePoint builds on WebForms
- Browser differences handled for you
Advantages:
- Supports RAD
- Facilitates development of data LOB applications
- Rich UI control libraries included and several third party vendor libraries available
- Fair learning curve for transitioning Windows developers
Disadvantages:
- UI logic coupled with business logic
- Difficult to unit test
- View state management is sometimes a concern
MVC
- Encourages traditional web development
- Total control of HTML markup
- Supports Unit Testing, TDD and Agile methodologies
- Encourages the use of design patterns by convention
- Extremely flexible and extensible
Advantages:
- Total control of HTML markup
- Encourages separation of concerns by convention
- No view state
- Easier to unit test
Disadvantages:
- Control of HTML creates a dependency on knowledge of HTML, Javascript and CSS programming
- Higher learning curves for traditional ASP.NET developers and transitioning Windows developers
- Limited third party vendor controls (aka extensions)
When starting a new project and deciding on which framework to use, consider the following:
- Will your web application be a small one?
- Do you anticipate changes down the road?
- Do you have a lot of time to develop the application?
- How much time do you have to dedicate to learning?
- Are there any third party vendor controls that you were anticipating the use of?
The questions above should help you decide which framework you should use for your next project. On the project I’m currently working on, the project is not necessarily a small one that I could develop and ship right away. I am anticipating changes down the road since the user requirements were not clear at the start of the project and I need to deploy the solution (at least on the intranet) in a relatively short amount of time. My employer is gracious enough allow me to learn and explore new technologies (which I took advantage of) and there were some third party vendor UI Controls that I needed to use in the project. With that said, I ultimately ended up settling on WebForms since the third party vendor UI Controls I needed to use did not have an MVC Extension equivalent. There was a way to use the server controls in the MVC project with the MVC flavored WebForms (different than traditional WebForms) but it required a work-around that I was not crazy about and this scenario was bound to come up again with unanticipated requirements.
Hope this helps on your next project.
PS: For whatever reason, if you have to choose WebForms over MVC but want to build a prescriptive application similar to MVC then take a look at ASP.NET WebFormsMVP. WebFormsMVP is an open source framework that enables the use of the Model-View-Presenter pattern by convention, like MVC and provides a very similar development experience.