Controller (System.Web.Mvc.Controller)
1.获取路由中的各个值
Request.RequestContext.RouteData.Values["id"]
1).:System.Web.Mvc.Controller > Controller类 > 它的属性
2.相关参考: 在cs代码中获取controller或action 值
//定义自己的HTML助手方法public static string IsActiveLi(this HtmlHelper html, string roleCode = null,string cssClass = null){ string currentController = (string)html.ViewContext.RouteData.Values["controller"]; var curActionName = (string)html.ViewContext.RouteData.Values["action"]; //略
3.如果action是 [ChildActionOnly] 即
@{Html.RenderAction("GenreMenu", "Store");}
我们需要在子controller和action拿到parent controller和action 上面的代码做调整
string currentController = (string)html.ViewContext.ParentActionViewContext.RouteData.Values["controller"]; //被ChildActionOnly调用var curActionName = (string)html.ViewContext.ParentActionViewContext.RouteData.Values["action"];
4.Get Current Area Name in View or Controller
object area;Request.RequestContext.RouteData.DataTokens.TryGetValue("area", out area);