Hesam Seyed Mousavi, Feb 26, 2013
The Model-View-Presenter (MVP) pattern places the emphasis on the view to control the flow of logic throughout the presentation layer. Three distinct parts make up the MVP pattern:
- The model represents the business data that is to be displayed by or modified by the view.
- The view displays the model data obtained via the presenter and delegates user input to the presenter.
- The presenter is called from the view to display data pulled from the model and to handle user input.
A framework has been built to enable the MVP pattern to be used with ASP.NET web forms. You can find more information by navigating to http://www.webformsmvp.com. You will create an implementation of the MVP pattern using web forms without the need of a framework.
The Front Controller acts as the initial point of contact for requests, centralizing all business functions and supporting infrastructure concerns such as authorization, security, and the rendering of views. The view in the Front Controller pattern is completely passive and is rendered by the command that handles the request. This ensures that little if any logic is contained within the views and certainly helps to avoid the code behind model supported out of the box by the web forms framework, which can lead to a muddle of concerns between your view and controller. Having a central controller detached from the views also helps to promote code reuse and the sharing of business logic. With presentation logic in one place, it becomes easy to change the actions of a request.
The Model-View-Controller (MVC) pattern, like the Model-View-Presenter pattern, separates an application into three main components: the model, the view, and the controller.
- The model represents the business data that the view is to display or modify.
- The controller can be an implementation of the FrontController pattern. It is the initial contact for a request handling all user interaction. It interacts with the model based on the request and selects the appropriate view to render.
- The view is passive and has no knowledge of the controller. It simply displays the model data supplied from the controller.
In the MVC pattern, views typically map to domain model entities; however, for this scenario in which the view requires data from many entities, a ViewModel can be used. A ViewModel is a class optimized for use with a specific view template, that it provides a flattened view of the domain, potentially exposing properties that do not exist within the domain model. A ViewModel also helps to detach the view from the underlying domain model and can be a lot more flexible than using real domain entities.
The ASP.NET MVC Framework
The ASP.NET MVC framework is Microsoft’s implementation of the MVC pattern, which offers an alternative method for creating ASP.NET sites. The framework is available as a separate install from http://www.asp.net/mvc/, and version ASP.NET MVC 2.0 is included in Visual Studio 2010 and ASP.NET MVC 4.0 is included in Visual Studio 2012 and also available as a new framework in Visual Studio 2010.