Not to mention nonsense, first of all, despise Baidu!! I can't search for anything, search for the same keyword, Google is the first answer, from Baidu search, it's all nonsense!!
sb Baidu !!
In the controller:In the controller class Controller in ASP.NET MVC, there is this read-only property:
Contains route information. The RouteData class belongs to the System.Web.Routing namespace. This indicates that this class is not a class exclusive to ASP.NET MVC, but belongs to the ASP.NET. ASP.NET MVC uses this route to start the controller and the corresponding action. Take a closer look at this RouteData type:
There is a Values property of type RouteValueDictionary that reads out the values of the route. We can use this property to get the value we want.
Write action code:
in View If in View, we can also get the ControllerContext completely through the value of the ViewContext property of the WebViewPage. The reason is that the ViewContext inherits from the ControllerContext.
The ControllerContext class has the RouteData property mentioned at the beginning of this article
In this way, we can display the names of the current controllers and actions in the view with the following code:
|