是否可以ViewContext从类库中访问?我需要获取当前View和Controller的动作名称.我在我的类库项目中添加了两个System.Web.dll,System.Web.Mvc但仍无法找到获得我需要的方法.虽然我可以使用访问当前上下文System.Web.HttpContext.Current.
The*_*Sky 10
您可以访问如下的当前路线信息:
var httpContext = new HttpContextWrapper(HttpContext.Current);
var routeData = System.Web.Routing.RouteTable.Routes.GetRouteData(httpContext);
var controllerName = routeData.Values["controller"].ToString();
var actionName = routeData.Values["action"].ToString();
Run Code Online (Sandbox Code Playgroud)