Implementation Process of ASP. net mvc Framework (2)

Source: Internet
Author: User

I. Basic concepts:
In traditional cases, http: // localhost/default. aspx indicates the request for the default. aspx file under the root directory of the website.
In ASP. net mvc, routing processes all requests, and then determines the Controller name, action name, and various parameters from the request URL.
The Controller executes the corresponding action, and the action processing logic or redirection. By default, No xxx. aspx file request is executed.
This is also the biggest difference between ASP. net mvc and traditional ASP. NET applications. The detailed process is as follows,
Ii. Framework execution sequence:


As shown in,
First, the user sends a URL request to the server through a web browser. The requested URL is no longer in XXX. aspx format, but http: // hostname/controllername/actionname/parameters.
This request is intercepted by the routing ing System of ASP. net mvc. The routing ing System parses the Controller name controllername, action name actionname and parameters according to the ing rules, and then looks for the controllernamecontroller under the controllers directory. CS controller class. By default, the system always looks for the Controller name + controller class under the controllers directory.
Then, find the method with the same name as actionname under this class, find it, PASS Parameters as a parameter to this method, and then the action method starts execution, the actionresult type (view, JSON, redirect, etc.) is returned after execution ).
One type of actionresult is view. By default, aspx files with the same name as controllername under the views directory are returned and viewdata is transmitted to the view. Viewdata generally contains the control value for controlling the view display and the data required for the view display. viewdata is one of the methods used to transmit data between the Controller and view.
Let's review the request process on the homepage in the previous article. The URL we passed is http: // localhost/home/index. Under the default routing rule, set controllername to "home" and actionname to "Index" without parameters.
Therefore, the system finds the index method of the homecontroller class under the controllers directory, and finds the method successfully.
This method calls the model to retrieve some data and put it in the corresponding viewdata key value. Then return to the view. The returned value is index. aspx under home under views.
The data in viewdata is displayed in a certain format, so a typical ASP. net mvc call is completed.

In the next article, we will detail URL routing.

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.