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