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"]
原文地址:https://www.cnblogs.com/dupeng0811/p/2890340.html