Search code examples
c#asp.net-mvcinternet-explorer-9

how to display View by browser type in asp.net mvc?


i use many css and javascript in my project which not support Only by IE9 browser,

so i create two verson for all view, First version for IE browser that does not have css and javascript, and second version for other browser that does all css and javascript.

i want if user browser is IE9 (only Version 9) then display firts view else display second View.


Solution

  • you must use Custom DisplayMode in mvc and User-agent in browsers.

    any browser have a unique user-agent that internet explorer 9 is "MSIE 9".

    if view name is First.cshtml,

    create view that is name: First.IE9.cshtml

    and in global.asax

    protected void Application_Start(){
    //other code
    
    DisplayModeProvider.Instance.Modes.Insert(0,new DefaultDisplayMode("IE9")
    {
        ContextCondition=context=> context.request.UserAgent.Contains("MSIE 9")
    });
    }