How do I detect a mobile browser in a .NET MVC3 application

后端 未结 3 937
一个人的身影
一个人的身影 2020-12-04 15:14

I\'m developing a .NET MVC3 application.

Is there a good way to detect if the user is using a mobile browser in the view (using RAZOR). I\'m wanting to differ the

3条回答
  •  遥遥无期
    2020-12-04 16:08

    I use this Method (Works fine for Me)

    if (eDurar.MobileDetect.DeviceType.Any(m => Request.UserAgent.Contains(m)))
    {
        Layout = "~/Views/Shared/_mobileLayout.cshtml";
        @Html.Partial("mobileIndex");
    
    }
    else
    {
        Layout = "~/Views/Shared/_Layout.cshtml";
        @Html.Partial("desktopIndex");
    }
    

    I suggest you to use responsive bootstrap something, avoiding mobile specific page is better

提交回复
热议问题