Freigeben über


Compatibility of ASP.NET Web Forms and ASP.NET MVC

If you are an experienced ASP.NET developer, much of your ASP.NET knowledge can be applied when you create ASP.NET MVC application. Because ASP.NET MVC is part of the ASP.NET framework, almost all ASP.NET namespaces, class, and interfaces can be used in MVC applications. This topic describes the strengths of both the ASP.NET Web Forms and ASP.NET MVC models. It then describes the ASP.NET framework features that you can use in an MVC application and those that you should avoid.

Strengths of ASP.NET Web Forms

The following list describes the strengths of the ASP.NET Web Forms model for building Web applications.

  • Event model. Web Forms supports an event-driven programming style that is like Windows applications. Many events are available, and they are supported by hundreds of server controls.

  • State management. Web Forms reduces the complexity of managing state by using view state and server-based controls.

  • Page-based architecture. Web Forms provides an architecture that combines a page with declarative markup (an .aspx file) with a code-behind file that adds functionality. This structure can make it easy to create pages that implement common tasks, such as responding to user gestures and rendering markup from server code.

  • Rich set of controls. The ASP.NET community has made available hundreds of server controls and components that reduce development time.

Strengths of ASP.NET MVC

The following list describes the strengths of the ASP.NET MVC model for building Web applications.

  • Separation of concerns. ASP.NET MVC enforces a "separation of concerns", in which the application is divided into discrete and loosely-bound parts—namely, the model, view, and controller parts of the application. This makes MVC applications easier to test and maintain.

  • More control of rendered HTML. MVC significantly increases your control over rendered HTML.

  • Test-driven development. MVC was designed to make test-driven development easier. You can create an MVC project and its test project at the same time. You can then create unit tests for each action method in your application, and run them without invoking the complete request cycle for a Web application.

ASP.NET Framework Features That Are Compatible with MVC

It might appear that Web Forms and MVC are very different technologies. However, both of these technologies are built on the ASP.NET framework. Therefore, most ASP.NET framework features that you have used to create applications that are based on Web Forms are also available to you for developing MVC applications. This includes features such as membership, authentication, roles, and configuration, which work the same way in an MVC application as they do in a Web Forms application. Most ASP.NET namespaces, classes, and interfaces can be used in an ASP.NET MVC application.

ASP.NET Framework Features That Are Incompatible with MVC

Because ASP.NET MVC does not maintain state information by using view state, you must find other ways to manage state information, if you need it. In addition, server controls that rely on view state and postback will not work as designed in an ASP.NET MVC application. Therefore, you should not use controls such as the GridView, Repeater, and DataList controls.

The life cycle of a Web Forms page is complex, during which many events occur. These events are not supported in an ASP.NET MVC application, because the interactions between the model, view, and controller use a different life-cycle model. For more information about the MVC life-cycle model, see Understanding the MVC Application Execution Process.

See Also

Other Resources

ASP.NET MVC Overview