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