The dotted line above indicates: passive role. Solid line representation: active role.
1. controllers and Views : Controllers and views are two-way relationships, but controller relationships are more proactive.
When the controller is the active role, the Controller decides which view to display, and when the view is active, the view can decide which of the action methods to return the data to, and when the data is needed by the graph, you can decide which controller method the data should be obtained from.
2. views and models : A view is an active role, and a model exists in the manner of a data provider. So the view to the model is implemented, and the model to the view is dashed.
The data on the view is basically transmitted from the method in the controller. However, the data categories that are passed in are basically defined in the model, so you can say that the view and the model are references to each other, that is, the view references the data dictionary definition in the model.
If the view finds that the data passed from the controller is not sufficient to display completely, then the view becomes active, that is, the model is active, and the data is queried to obtain the data. That is, in, see, view to model is solid line ...
3. controller and Model : The controller is always active, the controller is responsible for invoking the various data dictionaries defined in the model, and the model is simply providing data services, or validating the service to the controller.
Well, in summary: That is, the user sent over the request, first through the routing, routing mechanism, judge the request is which controller in which method, then the controller, call the model data dictionary definition, after obtaining data, decide which view to display. That's probably the way it went.
OK, now look, if you create the first MVC program.
Here, I'm using VS2013, open VS2013, select File-"New--" project
Then select the Blank template
After the first good project, the initialized template is:
Next, we create a new controller home, modify the default generated code
The code is as follows:
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSYSTEM.WEB.MVC;namespacefirstmvc.controllers{ Public classHomecontroller:controller {//Get:home Public stringIndex () {return "welcome, this is ASP. NET MVC"; } }}
Then we run the code and we get the result, and this is our first simple little program that can't be simpler:
Summary the main understanding of MVC concept.
MVC Learning Series What is MVC