Introduction to ASP. NET MVC

Source: Internet
Author: User
Tags what is asp

1 what is ASP. NET MVC?

ASP. NET MVC is the official Microsoft-provided MVC-based Web application (Web application) framework, which is castle by monorail, and the latest version is ASP. NET MVC 4.0. is to decompose a Web application into: Model, view, and controller. The ASP. NET MVC Framework provides an MVC-based design pattern that can be used in place of ASP. WebForm.

Advantages of MVC:

(1), by dividing the project into model, view and controller, make complex projects easier to maintain, reduce the coupling between projects;

(2), do not use ViewState and server form control, you can more easily control the behavior of the application;

(3), the application through the controller to control the request, and provides the native urlrouting function to rewrite the URL;

(4), so that the Web program support for unit testing better;

(5), in the team development model performance more outstanding.

2. MVC contains key technologies:

return type of Actionresult:action

Filter: Filters

Modelbinder:model binding Device

URL Routing:url Routing Rules

3. The implementation phase of the MVC Web project:

Stage

More information

Receive the first request to an application

In the Global.asax file, the Route object is added to the RouteTable object.

Executing a route

The UrlRoutingModule module uses the first matching Route object in the RouteTable collection to create the Routedata object, and then creates the RequestContext object with the created object

Create an MVC request handler

The Mvcroutehandler object creates an instance of the Mvchandler class and passes the RequestContext instance to the handler

Create a Controller

The Mvchandler object uses the RequestContext instance to identify the Icontrollerfactory object that is used to create the controller instance (typically an instance of the Defaultcontrollerfactory class)

Execution controller

Mvchandler instance calls the controller's Execute method

Invoke operation

For a controller that inherits from the Controllerbase class, the Controlleractioninvoker object associated with the controller determines the action method to invoke the Controller class, and then calls the method

Execution results

The action method receives the user input, prepares the appropriate response data, and then executes the result by returning the result type. The built-in result types that are executable include: ViewResult (renders view and is the most commonly used result type), Redirecttorouteresult, Redirectresult, Contentresult, Jsonresult, Fileresult and Emptyresult

A simple description:

Step 1: Create the RouteTable

The first step occurs when the ASP. NET application starts for the first time. RouteTable maps the URL to handler.

Step 2:urlroutingmodule Intercept Request

The second step occurs when we initiate the request. UrlRoutingModule intercepts each request and creates and executes the appropriate handler.

Step 3: Execute Mvchandler

Mvchandler creates the controller and passes the controller in to ControllerContext, then executes the controller.

Step 4: Execute the Controller

The controller detects the Controller method to be executed, constructs the parameter list, and executes the method.

Step 5: Call the Renderview method

In most cases, the Controller method calls Renderview () to render the content back to the browser. The Controller.renderview () method delegates the work to a viewengine.

Introduction to ASP. NET 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.