本文介绍了如何获取当前的viewName(不是动作名)在ASP .NET MVC3(测试版)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用国际化的,我需要当前视图名(不actionname),这样我就可以相应地显示该选定特定文化的观点。
保护覆盖无效OnActionExecuted(ActionExecutedContext filterContext)
{
字符串cultureName = Thread.CurrentThread.CurrentCulture.Name;
//字符串ViewNameOnly =做一些事情来获得的viewName
如果(string.IsNullOrEmpty(ViewNameOnly))
ViewNameOnly = filterContext.RouteData.Values [行动] +。 + cultureName; }
解决方案
保护覆盖无效OnActionExecuted(ActionExecutedContext filterContext)
{
ViewResultBase视图= filterContext.Result为ViewResultBase;
如果(查看!= NULL){
字符串的viewName = view.ViewName;
}
}
I want to use Internationalization for that i need current viewname(not actionname) so that i can accordingly display specific view for that selected culture.
protected override void OnActionExecuted(ActionExecutedContext filterContext)
{
string cultureName = Thread.CurrentThread.CurrentCulture.Name;
//String ViewNameOnly= do something to get viewName
if (string.IsNullOrEmpty(ViewNameOnly))
ViewNameOnly= filterContext.RouteData.Values["action"] + "." + cultureName;
}
解决方案
protected override void OnActionExecuted(ActionExecutedContext filterContext)
{
ViewResultBase view = filterContext.Result as ViewResultBase;
if (view != null) {
string viewName = view.ViewName;
}
}
这篇关于如何获取当前的viewName(不是动作名)在ASP .NET MVC3(测试版)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!