MVC Learning Series 1 -- What is MVC, Learning Series 1 -- mvc

Source: Internet
Author: User

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.

 

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.