MVC中获取当前htmlhelper的Controller和Action
string controllerName = (string)htmlHelper.ViewContext.RouteData.GetRequiredString("controller"); string areaName = (string)htmlHelper.ViewContext.RouteData.DataTokens["area"];
在 controller 中可以使用 ControllerContext 取得:
|
1
2
|
ControllerContext.RouteData.Values["controller"]ControllerContext.RouteData.Values["action"] |
在 view 中可以使用 ViewContext:
|
1
2
|
ViewContext.RouteData.Values["controller"]ViewContext.RouteData.Values["action"] |
|
🐳 作者:dupeng0811 📢 版权:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接 💬 留言:同时 , 如果文中有什么错误,欢迎指出。以免更多的人被误导。 |
|

浙公网安备 33010602011771号