ASP. net mvc area operation

Source: Internet
Author: User

ASP. net mvc area operation

* 1. Create an area: Right-click and choose add> area...
* 2. inherit arearegistration and configure the route corresponding to this area
* 3. Register this area in global through arearegistration. registerallareas ();
* 4. With area, you must configure the routing namespace.

Using system. Web. MVC;

Namespace mvc20.areas. asynchronouscontroller

{

// When an area is created, the class inherited from arearegistration is automatically generated.

// If you need to use MVC in this area, you need to use arearegistration. registerallareas () in global ();

Public class asynchronouscontrollerarearegistration: arearegistration

{

Public override string areaname

{

Get

{

Return "asynchronouscontroller ";

}

}

Public override void registerarea (arearegistrationcontext context)

{

// Set the namespace (4th parameters in this example) When configuring routes in the area)

Context. maproute (

"Asynchronouscontroller_default ",

"Asynchronouscontroller/{controller}/{action}/{ID }",

New {controller = "home", Action = "Index", id = urlparameter. optional}, // parameter defaults

New String [] {"mvc20.areas. asynchronouscontroller. controllers "}

);

}

}

}

Global. asax

Code

Using system;

Using system. Collections. Generic;

Using system. LINQ;

Using system. Web;

Using system. Web. MVC;

Using system. Web. Routing;

Namespace mvc20

{

Public class mvcapplication: system. Web. httpapplication

{

Public static void registerroutes (routecollection routes)

{

Routes. ignoreroute ("{resource}. axd/{* pathinfo }");

// This project uses area. Therefore, when configuring a route, you must set a namespace (4th parameters in this example)

Routes. maproute (

"Default", // route name

"{Controller}/{action}/{ID}", // URL with Parameters

New {controller = "home", Action = "Index", id = urlparameter. optional}, // urlparameter. optional-if the value of a parameter cannot be obtained from the URL route, the value of this parameter is obtained from the URL parameter.

New String [] {"mvc?controllers "}

);

}

Protected void application_start ()

{

// Register this applicationProgramAll areas in

Arearegistration. registerallareas ();

Registerroutes (routetable. routes );

}

}

}

'Mso-��-o83 �� 0.5pt; font-family: "segoe UI", "Sans-serif"; color: black; Background: # ddedfb '>False;

}

Return True;

}

}

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.