Chapter 12. Best of Both Worlds: Web Forms and MVC Together

Many people wonder if it is possible to work with both ASP.NET MVC and ASP.NET Web Forms in the same web application. The answer, thankfully, is rather short: Yes, you can work with both platforms in one application. The reason you can do this is because they are both distinct layers on top of core ASP.NET that do not interfere with each other. Once this question is asked (and, thankfully, answered), many observers have a follow-up: "Why in the world would you do this?"

There are various reasons why you might want to run one Project type from within another. For example:

  • Web Forms is very good at encapsulating view logic into components. You may have a need to show a complex reporting page, or perhaps a portal page, and you'd like to flex components you already know how to use.

  • ASP.NET MVC is very good at allowing you to test the logic in your web application. Your company may have a code-coverage policy that dictates that 90 percent of all code written must be covered by a unit test. MVC can help you with this.

  • You may be migrating an existing application to ASP.NET MVC and not want to do it all in one development cycle. Having the ability to add ASP.NET MVC to your application and slowly roll it over is a tremendous benefit.

You may have your own reasons that differ from the ones we made up here; the good news is that the ASP.NET team went out of their way to make this possible for you.

HOW IS IT POSSIBLE?

The ASP.NET MVC team ...

Get Professional ASP.NET MVC 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.