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

后端 未结 3 944
一个人的身影
一个人的身影 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 15:55

    MVC3 exposes an IsMobileDevice flag in the Request.Browser object.

    So in your razor code, you can query this variable and render accordingly.

    For example, in your view (razor):

    @if (Request.Browser.IsMobileDevice) {
      
    } else {
      
    }
    

提交回复
热议问题