微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – MVC 4移动和平板电脑视图分离

我正在尝试为平板电脑和移动设备制作单独的视图.在app_start我有这个代码
displayModeProvider.Instance.Modes.Insert(0,new
        DefaultdisplayMode("Tablet")
        {
            ContextCondition = (ctx =>
            ctx.Request.UserAgent.IndexOf("iPad",StringComparison.OrdinalIgnoreCase) >= 0 ||
            ctx.Request.UserAgent.IndexOf("Android",StringComparison.OrdinalIgnoreCase) >= 0)
        });

我创建了两个布局文件,一个用于移动设备,另一个用于平板电脑.但是当我从Android上的移动设备访问时存在冲突.它将我重定向到layout.tablet.我怎么能分开这两个设备?

解决方法

我在浏览器中使用用户代理切换器对此进行了测试,它运行正常.
displayModeProvider.Instance.Modes.Insert(0,StringComparison.OrdinalIgnoreCase) >= 0 && 
            ctx.Request.UserAgent.IndexOf("mobile",StringComparison.OrdinalIgnoreCase) < 1)
        });

        displayModeProvider.Instance.Modes.Insert(1,new DefaultdisplayMode("Mobile")
        {
            ContextCondition = (ctx =>
                ctx.Getoverriddenbrowser().IsMobileDevice)
        });

原文地址:https://www.jb51.cc/csharp/243082.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐