Pro ASP. net mvc 3 framework study Note 3 [MVC mode Introduction]

Source: Internet
Author: User
Tags create domain ruby on rails

Topic: MVC Mode

1. History of MVC:

The Model-View-controller concept was used in 1970s. MVC was proposed from the Smalltalk project. Therefore, the original MVC pattern contains very good details that are closely related to the specific concepts of the Smalltalk project. We assume that the view is stateless, and the interaction with the MVC application follows this process: the user generates an action to update the view, this is exactly the same as the nature of Web applications through HTTP requests and responses. In addition, MVC emphasizes the idea of decomposing concerns-loose coupling between the domain model and control logic and the UI, which means that a large number of HTML parts can exist independently, this makes maintenance and testing easier. Of course, this is what Ruby on Rails has always admired and advocated in MVC. It is also an advantage of many other MVC frameworks, including the ASP. net mvc framework.

2. Understand the MVC mode:

Models: controls or presents the data processed by the user (users). It can be a view model that is only used to present data transmitted between the view and the Controller; it can also be relatively complex in the business field, used to execute operations, transfer, and process rule data.

Views: As the UI, it is responsible for presenting data to the client, that is, the final HTML page.
Controllers: process the request, perform the model operation, and select a view to present the model data to the browser or the user.

Models defines the environment in which the entire application works. For example, in a banking system, the model represents everything supported by the program, such as the general ledger and the customer's credit limit, as well as all operations that can be used to manipulate data (such as deposit and withdrawal operations), we are increasingly aware of the importance of models for the entire MVC application.

Models can also be understood from the aspects that it is not responsible for. For example, it is not responsible for rendering the UI and processing various requests. These are the work of views and controllers, in addition to displaying model members, views has nothing to do with users. That is to say, views do not know the existence of models and do not have any direct contact with models. Controllers is the bridge between views and models. When there is a request from the client, controllers selects an appropriate view to respond to the user's request.

If necessary, some necessary operations are also implemented in models. It can be said that every part of the MVC Architecture has been well defined and divided, which is exactly the idea of "decomposition focus" That MVC has been implementing: The logic for data control is included in models; the presentation logic of data is included in views. The logic for processing user requests and input is included in controllers. With such a clear division of labor, our programs will become easier to maintain and expand, even after the system is very large.

3. Understand Domain Model)

As mentioned earlier, the most important part of MVC is domain model (as mentioned in the previous notes about domain model ), we create models based on the real-world entities, operations, and rules that must be supported by applications in industries or activities. The created model can also be called domain model. For developers using C #, domain model is a set of C # types (classes, structures, etc.). These are collectively referred to as domain types ). the methods defined in the domain type indicate various operations on the domain, and the domain rules are also expressed in these methods. When we create a domain type) when you create a domain object, the domain model is usually persistent. Of course, there are many persistence methods, usually using relational databases.

To further break down the domain model of ASP. net mvc applications, the model is placed in different C # assemblies. In this way, we can create domain models from other parts of the program, which is particularly useful for large-scale projects.

4. MVC implementation of ASP. NET

In MVC, controllers is a C # class, which generally inherits system. web. MVC. controller class. Every public method is called Action method. These action methods are implemented through ASP. net Routing System (Routing System) is associated with configurable URLs. To implement some operations in the domain model, the statements in controllers are executed, and a view is selected to be presented to the client. The figure below shows a process like this:


From the above figure, we can also clearly see that the view does not rely on the controller, and does not know the existence of the controller, so it will not have direct contact. ASP. net mvc3 provides a new view engine-razor. Of course, the previous aspx view engine can still be used directly. In MVC, we can choose any method to implement domain model, without any restrictions.

The traditional three-tier architecture is illustrated as follows:


In comparison, we can also appreciate some advantages of the MVC Architecture.

The traditional three-tier architecture is also a huge leap. Nowadays, it is widely used in various business systems. There is no limit on how to implement the corresponding UI, whether you are winform, webfrom, or others. In the case of no complexity, it provides a breakdown of the focus. It is easier to create unit tests for the Dal. In addition, the layer-3 architecture looks very similar to MVC, but MVC and layer-3 are completely different. Do not confuse them. According to Lao Zhao's description in msdn (I have read several related msdn MVC tutorials), MVC is a rendering mode, while Layer 3 is an architecture mode.

Corresponding to Layer 3: When our UI Layer
Coupled with button events, automated unit tests are almost impossible.

5. MVC also has many variants.For example, Model-View-presenter pattern (MVP mode) and Model-View-view model pattern (mvvm Mode)

Take note of today.

I have just learned MVC. I certainly have some mistakes in understanding the book. please correct me if you are passing by. Thank you.

Wish the passing friends a smooth job!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.