How can i detect if the request is coming from a mobile browser in my asp.net MVC 3

前端 未结 10 1955
旧时难觅i
旧时难觅i 2020-12-14 08:11

what i am trying to achieve is simple; Among all the view which i have in my web application, i have only two razor views that i have created a mobile version for them. so i

10条回答
  •  时光说笑
    2020-12-14 09:10

    I use this method to detect mobile and desktop

    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");
    }
    

提交回复
热议问题