我正在创建这个ASP.Net mvc4 application..In,我想在桌面版本上为不同的浏览器加载不同的视图。
在mvc4中,我们可以为桌面和移动设备加载不同的视图,但在这里,我想为桌面浏览器加载不同的视图,并且在相同的浏览器中加载不同的视图,例如
桌面铬与桌面IE9桌面IE8与桌面IE9
有谁可以帮我?
提前谢谢。
发布于 2013-05-22 15:49:21
就我个人而言,我不认为每个桌面浏览器都有不同的View
是可行的,你试图解决的问题可能是Css
/JavaScript
问题,而与View
无关,它基本上应该包含内容,而不是功能/设计。
但是,您可以利用新的DisplayModeProvider
机制(在MVC4中):
在你的Global.asax
中
protected void Application_Start()
{
// Internet Explorer 9 (view prefix will be "ie9")
DisplayModeProvider.Instance.Modes.Add(new DefaultDisplayMode("ie9")
{
ContextCondition = (context => context.GetOverriddenUserAgent().IndexOf("MSIE 9.", StringComparison.OrdinalIgnoreCase) >= 0)
});
// Internet Explorer 8 (view prefix will be "ie8")
DisplayModeProvider.Instance.Modes.Add(new DefaultDisplayMode("ie8")
{
ContextCondition = (context => context.GetOverriddenUserAgent().IndexOf("MSIE 8.", StringComparison.OrdinalIgnoreCase) >= 0)
});
// Internet Explorer 7 (view prefix will be "ie7")
DisplayModeProvider.Instance.Modes.Add(new DefaultDisplayMode("ie7")
{
ContextCondition = (context => context.GetOverriddenUserAgent().IndexOf("MSIE 7.", StringComparison.OrdinalIgnoreCase) >= 0)
});
// Google Chrome (view prefix will be "chrome")
DisplayModeProvider.Instance.Modes.Add(new DefaultDisplayMode("chrome")
{
ContextCondition = (context => context.GetOverriddenUserAgent().IndexOf("Chrome", StringComparison.OrdinalIgnoreCase) >= 0)
});
// Mozilla Firefox (view prefix will be "firefox")
DisplayModeProvider.Instance.Modes.Add(new DefaultDisplayMode("firefox")
{
ContextCondition = (context => context.GetOverriddenUserAgent().IndexOf("Firefox", StringComparison.OrdinalIgnoreCase) >= 0)
});
在您的Views
文件夹中:
/Views/[Controler]/[Action].ie9.cshtml
/Views/[Controler]/[Action].ie8.cshtml
/Views/[Controler]/[Action].ie7.cshtml
/Views/[Controler]/[Action].chrome.cshtml
/Views/[Controler]/[Action].firefox.cshtml
发布于 2013-05-22 15:32:12
this能帮到你吗?
或者,如果您想在视图中了解浏览器,也可以使用jQuery.browser插件
https://stackoverflow.com/questions/16685800
复制相似问题