2

I am creating ASP.Net mvc4 application..In this, I want to load different views for different browsers on desktop version..

In mvc4 we can load different views for desktop vs. mobile but here I want to load different views for desktop browsers and in same browser but different versions like

desktop chrome vs. desktop IE9 desktop IE8 vs. desktop IE9

Can anyone help me?

Thanks in advance.

aagrawal
  • 45
  • 7

2 Answers2

2

Personally, i don't think different View for each desktop browser is the way to go, the problems you're trying to address are probably Css/JavaScript issues and not related to the View which basically should contain content and not functionality / design.

However, you can leverage the new DisplayModeProvider mechanism (in MVC 4):

In your 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)
        });

In your Views folder:

  /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
haim770
  • 48,394
  • 7
  • 105
  • 133
0

Can this help you?

Or you can use jQuery.browser plugin if you want to know browser in View

Community
  • 1
  • 1
Sergey Shabanov
  • 176
  • 2
  • 11
  • 1
    Hi Sergey, Thanks for your reply...I can do this manually but here I want to do this using MVC4 in-build functionality (DisplayModeProvider) that works to load different views for desktop and mobile.. – aagrawal May 22 '13 at 07:38