MVC Learning Series 1 -- What is MVC, Learning Series 1 -- mvc
The dotted line above indicates a passive role. Indicates an active role.
1.Controllers and views: The relationship between the Controller and the view is bidirectional, but the relationship between the controller is more active.
When the controller is an active role, the Controller determines which View to display. When the View is an active role, the View determines which Action method to return data to the Controller, in addition, when a Data graph requires data, you can determine the method of the controller from which the data should be obtained.
2.Views and Models: Views are active roles, while models exist as data providers. Therefore, view-to-model is implemented, and model-to-view is dotted.
The data in the view is basically transmitted from the method in the controller. However, the passed data type is basically defined in the model. Therefore, we can say that the relationship between views and models is mutual reference, that is, the view will refer to the data dictionary definition in the model.
If the view finds that the data transmitted from the controller is not fully displayed, the view becomes active, that is, the model is actively queried to obtain data. That is, in the middle, the view to the model is solid ..
3.Controllers and Models: The controller is always an active relationship. The Controller is responsible for calling various data dictionaries defined in the model. The model only provides data services or verifies services for the controller.
Well, in summary: that is, the request sent by the user first uses the routing and routing mechanism to determine which method of the Request controller is and then the controller, call the data dictionary definition in the Model. After obtaining the data, you can decide which view to display. This is probably the case.
Now let's take a look. If you create the first MVC program.
Here, I use VS2013, open VS2013, select file --> New --> Project
Select a blank template.
After the project is ready, the initialization template is:
Next, we will create a new controller Home and modify the default generated code.
The Code is as follows:
Using System; using System. collections. generic; using System. linq; using System. web; using System. web. mvc; namespace FirstMVC. controllers {public class HomeController: Controller {// GET: Home public string Index () {return "Welcome, ASP. net mvc ";}}}
Next, we run the code to get the result. This is our first simple small program:
Summary: Mainly understanding the concept of MVC.