3.3. The Model View Controller Pattern

MVC is a design pattern aimed at describing how you can separate your applications and decouple your system. MVC is the three separate sections of an application. Model refers to the domain of the system. This model represents information that will be used by the application. For example, in this system you will have models such as Product, Order, and ShoppingCart. These objects will store all the information related to that section of the problem domain. View relates to the UI and displays the model to the user. An example would be a web page, or a desktop form. As MVC is an architectural pattern, it is not constrained to a particular implementation, framework, or language and can be used to describe how to structure both web and desktop applications. Finally, controller processes requests from the user and updates the model before returning it to the view to display. The controller will have various methods to control what to display. For example, the controller might be called HomeController, with a method called Index that will set up the model for the Index page before sending the rendered page down to the end-user.

When a request comes in, it will hit the controller first. The controller will construct and populate the model. It will then pass the model to the view. The view will then communicate with the model to display the data. The view might also communicate with the controller to process further questions. Figure 3-1 represents ...

Get Testing ASP.NET Web Applications 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.