MVC before and after get action, Controller, id name method and routing rules

Source: Internet
Author: User

Get action, Controller, id name method on front and rear stations
    • Front page: viewcontext.routedata.values["Action"]. ToString ();//Get Action name

viewcontext.routedata.values["Controller"]. ToString ();//Get Controller name

viewcontext.routedata.values["ID"]. ToString ();//Gets the route parameter value:

    • Background page: ControllerContext.RouteData.GetRequiredString ("Action");

ControllerContext.RouteData.GetRequiredString ("Controller");

ControllerContext.RouteData.GetRequiredString ("id");

Routing Rules Example

Routing rules are prioritized, with higher precedence.

routes. MapRoute (Name:"Test", URL:"Test1/{action}/{id}", defaults:New{controller ="Test", action ="Index", id =urlparameter.optional}); Routes. MapRoute (Name:"Datacenter", URL:"Data/{action}", defaults:New{controller ="DataCenter", action ="Index", id =urlparameter.optional}); Routes. MapRoute (Name:"Default", URL:"{Controller}/{action}/{id}", defaults:New{controller ="Home", action ="Index", id =urlparameter.optional});

When accessing: The/test1 page matches to the first routing rule, corresponding to the controller and behavior: Test/index. Access.. When/test1/add, the corresponding Test/add

When accessing: The/data page is matched to the second routing rule, corresponding to the controller and behavior: Datacenter/index. Access.. When/data/add, the corresponding Datacenter/add

When accessing: /test or. /datacenter or. /is matched to the third routing rule, and the third routing rule is automatically generated by the system

MVC before and after get action, Controller, id name method and routing rules

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.