This is part 1 of a 3-part series comparing ASP.NET MVC and Web Forms as a paradigm for ASP.NET websites. The purpose of this series is not to choose one technology versus the other, but rather to point out each of their strong points and equip the reader with enough information to make the appropriate decision when selecting which tool to use for their next web application project.
I recently presented on this topic at the Dallas Techfest and was very surprised by two things: (1) the increased interest in MVC, and (2) the number of people who have no plans to adopt MVC for new web application projects at their jobs and client engagements.
While those two points are juxtaposing, they indicate that a lot of people, simply put, just don’t know the advantages of the MVC pattern and how to sell those to the business owners and the rest of their team, in order to get buy in. This post will provide you with some major pointers to help in making the case for ASP.NET MVC.
MVC is a mature design pattern, dating back to 1979 from the Xerox PARC. It conveys the idea that your presentation should be ignorant of your business and domain logic – in other words, it enforces separation of concerns. In the MVC world, web requests are received and “dispatched” by the “controller” which is in charge of communicating with the business logic to retrieve data and then to pass this data, the “model”, to the presentation layer, the “view”.
Integrate applications across the enterprise for improved data integrity and consistent processes
What does this buy us, might you ask? Well, it fosters the adoption of best practices and good software development patterns, such as:
Separation of Concerns
Unit Test/TDD and Type Mocking
Loosely coupled tiers
Highly maintainable code
Better code organization
The ASP.NET MVC framework is built on top of a mature web stack and, thus, provides the developer with all the goodness that comes with ASP.NET, such as Session State, Caching, Profiles, Security and Membership, Master pages, Localization, Configuration, Health Monitoring, Tracing, and more.
When opting to develop your applications with MVC, you are not throwing away years of investment into a platform, but rather increasing the ability to write BETTER code.
It’s true that MVC forces the developer to rethink their strategy for handling web requests by ditching Viewstate and Postbacks, but it also embraces the web for what it is: a stateless protocol. It doesn’t try to shield the developer from that truth by introducing complex event lifecycles and bloated response payloads. Furthermore, it makes it much easier to adopt newer client and browser scripting frameworks, such as jQuery, while giving the developer full control of their mark up.
Additionally, as a side effect of having full control of your markup, you have better opportunities to do search engine optimization (SEO). Most search engines use a combination of criteria to rank pages. Web pages that yield better, lighter, semantic HTML markup have a better chance to rank higher in search results.
While MVC has many advantages, one must consider the learning curve required when jumping in from Web Forms. There’s a significant amount of knowledge to be gained by the web developer in order to fully understand this paradigm in ASP.NET. Web Forms developers have spent most of the last decade writing code to handle postbacks, and relying on viewstate to make some magic happen with their web pages. It’s hard to throw all of that out the window, and get closer to the metal. Let’s face it – Web Forms made it easy to create new web application! Debating whether MVC is better than Web Forms is likely a pointless debate, and is best left to the web zealots.