Basic data transfer in primary knowledge MVC,MVC

Source: Internet
Author: User

?

?

?

MVC is a form of representation that divides a Web application into three components: a view controller (model).

M:model is primarily a component that stores or processes data

V:view is a user interface layer component. The main task is to provide an HTML template and display the data obtained in the controller to the page where the cshtml file is used to handle the view.

C:controller handles the user interaction, handles the business, and gets the data into the model, which is then handed to the view.

?

?

?

ASPX is a foreground page class and a Background page class, the foreground page class inherits the background page class, so we can access the object in the background through <%%> in the foreground. After the user enters the URL address in the browser, the browser will go to the request server, if it is a dynamic ASPX page, will be handed over to the. NET framwork framework to handle, the server will create a HttpHandler to process the request, and through a series of pipeline events, In the eighth pipeline, a page class object is created, the page control tree is built, and the ProcessRequest () method of the background class is called between the 11th and 12 pipelines, and the page is sent to the browser after some processing.

MVC is a way to access the Controller class through {Controller}/{action}/{id}. The browser gets the URL first to find the Controller class, if present, find the following action method. If there are parameters that can pass parameters and then handle the business logic in the action method, then the action method determines which view to return. MVC enables the separation of pages from data, reduces coupling, makes operations more flexible, and is more efficient than ASPX because there is no series of pipelines.

There are many ways in which MVC passes data, but it is essentially the same.

?

In the controller class we can write a lot of methods, if you need to return to the view, you need to use the view method. View has many overloads, and you can select the view to return by using parameters. Pass an example of a parameter to return to the view display.

?

First Type: Request view

?

View

How do we write the method in the controller class and pass it to the view? Look through the source code, it will be very intuitive.

This is the compiled assembly to show the source code, where the compiler compiles the entire cshtml file into a class, usually encountered tags (automatic recognition of angle brackets (<>)). The Begincontext method that calls the parent class's webviewpage to indicate that the label should be added to the "~/views/home/stulist.cshtml" on this page, usually encountered C # code, then directly input. Then we click into the parent class, the following part of the parent source

?

We found the model, and we'll see how he got it.

The original is bound to ViewData above the dynamic properties ah, but the value of ViewData from where Ah, continue to look down

This time we see, _viewdata attribute, turn to the previous picture, this class does not define a _viewdata attribute? The value of the original view from this variable, and so on, the value of this variable who gave it?

This is the method, which is estimated to call this method when the Controller class invokes the method, and assigns the model property value of the Controller class to the model property of the view. This completes the process of numerical transfer.

The MVC pass value is passed like this, but it's impossible for us to just wear an object in it, MVC expands out a dynamic class and an object of two array types are available for us to use.

It is

ViewBag (Dynamic Class) Viewdata,tempdata.

The model passed is just a dynamic property on the load viewbag, so we can add any property to ViewBag to understand the dynamic class see (http://www.cnblogs.com/ljp-sun/p/4385409.html) in the view, It would be nice to take it in the same way.

Specific usage

Controller class

View

Summarize:

    1. MVC is a design pattern that, unlike ASPX, divides a Web program into three parts: a controller, a view, a model. When a request occurs, the server first goes to the controller and then finds the method inside, and the method decides what view to call.
    2. MVC passes data through the addition of dynamic attributes, which are not identical to the data objects in the Controller class and view, but when the view is invoked, the controller assigns the corresponding property values to the corresponding attributes in the view.

Basic data transfer in primary knowledge MVC,MVC

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.