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

Source: Internet
Author: User

1. Get action, Controller, id name method in front and rear station

Front page: viewcontext.routedata.values["Action"]. ToString ();

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

viewcontext.routedata.values["ID"]. ToString ();

Background page: routedata.getrequiredstring ("Action");

Routedata.getrequiredstring ("Controller");

Routedata.getrequiredstring ("id");

2. Example routing rules

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 routing rules and before and after get action, Controller, id name method

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.