【发布时间】:2013-05-22 07:24:03
【问题描述】:
我正在创建 ASP.Net mvc4 应用程序..在此,我想在桌面版本上为不同的浏览器加载不同的视图..
在 mvc4 中,我们可以为桌面和移动设备加载不同的视图,但在这里我想为桌面浏览器和相同的浏览器加载不同的视图,但不同的版本如
桌面 chrome 与桌面 IE9 桌面 IE8 与桌面 IE9
谁能帮帮我?
提前致谢。
【问题讨论】:
标签: c# asp.net-mvc-4 view
我正在创建 ASP.Net mvc4 应用程序..在此,我想在桌面版本上为不同的浏览器加载不同的视图..
在 mvc4 中,我们可以为桌面和移动设备加载不同的视图,但在这里我想为桌面浏览器和相同的浏览器加载不同的视图,但不同的版本如
桌面 chrome 与桌面 IE9 桌面 IE8 与桌面 IE9
谁能帮帮我?
提前致谢。
【问题讨论】:
标签: c# asp.net-mvc-4 view
就个人而言,我不认为每个 桌面 浏览器都有不同的 View 是要走的路,您要解决的问题可能是 Css/JavaScript 问题和与基本上应该包含内容而不是功能/设计的View 无关。
但是,您可以利用新的 DisplayModeProvider 机制(在 MVC 4 中):
在你的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
【讨论】:
this可以帮到你吗?
如果你想在View中了解浏览器,你可以使用jQuery.browser插件
【讨论】: