本文介绍了如何检测手机浏览器在.NET应用程序MVC3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个.NET应用程序MVC3。

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 display logic if it's a mobile browser.

谢谢!

推荐答案

MVC3暴露了IsMobileDevice国旗在的Request.Browser对象。

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

因此​​,在您的剃须刀code,可以查询这个变量,并相应地呈现。

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

例如,在你看来(剃刀):

For example, in your view (razor):

@if (Request.Browser.IsMobileDevice) {
  <!-- HTML here for mobile device -->
} else {
  <!-- HTML for desktop device -->
}

这篇关于如何检测手机浏览器在.NET应用程序MVC3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-24 00:35