在MVC3,如何让当前的动作叫什么名字? [英] In MVC3, how to get the current action name?
本文介绍了在MVC3,如何让当前的动作叫什么名字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法使用的HttpContext或查看上下文来获得当前操作名称的方式?
我可以用得到的控制器名称
VAR routeValues = HttpContext.Current.Request.RequestContext.RouteData.Values; 如果(routeValues!= NULL)
{
如果(routeValues.ContainsKey(控制器))
{
。controllerName = HttpContext.Current.Request.RequestContext.RouteData.Values [控制器]的ToString();
}
}
}
解决方案
VAR routeValues = HttpContext.Current.Request.RequestContext.RouteData.Values;
如果(routeValues!= NULL)
{
如果(routeValues.ContainsKey(行动))
{
。VAR actionName = routeValues [行动]的ToString();
}
}
Is there a way to use HttpContext or the View context to get the current action name?
I can get the controller name using
var routeValues = HttpContext.Current.Request.RequestContext.RouteData.Values;
if (routeValues != null)
{
if (routeValues.ContainsKey("controller"))
{
controllerName = HttpContext.Current.Request.RequestContext.RouteData.Values["controller"].ToString();
}
}
}
解决方案
var routeValues = HttpContext.Current.Request.RequestContext.RouteData.Values;
if (routeValues != null)
{
if (routeValues.ContainsKey("action"))
{
var actionName = routeValues["action"].ToString();
}
}
这篇关于在MVC3,如何让当前的动作叫什么名字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文