asp.net mvc 移动端视图自动切换
protected void Application_Start() { //自动切换移动端页面 DefaultDisplayMode mode = new DefaultDisplayMode("mobile") { ContextCondition = c => c.GetOverriddenUserAgent().IndexOf("iPhone", StringComparison.OrdinalIgnoreCase) >= 0 || c.GetOverriddenUserAgent().IndexOf("iPad", StringComparison.OrdinalIgnoreCase) >= 0 || c.GetOverriddenUserAgent().IndexOf("Android", StringComparison.OrdinalIgnoreCase) >= 0 || c.GetOverriddenUserAgent().IndexOf(" Mobile", StringComparison.OrdinalIgnoreCase) >= 0 }; DisplayModeProvider.Instance.Modes.Insert(0, mode); }
当使用移动设备浏览网页时,将优先查找对应移动端视图 *.mobile.cshtml 。比如 Index.mobile.cshtml 。
Categories:
.net
Tags:
代码
, asp.net mvc
已禁用评论。