Mobile layout of MVC View display mode and mvc View display Layout

Source: Internet
Author: User

Mobile layout of MVC View display mode and mvc View display Layout

Reference: http://www.cnblogs.com/dunitian/p/5218140.html

 

Easy to use

Create an MVC project and add the following code to golbal. asax:

 

1 // Add a custom suffix 2 DisplayModeProvider. instance. modes. insert (0, new defadisplaydisplaymode ("iphone") 3 {4 ContextCondition = (Context) => Context. request. userAgent. contains ("iphone") 5 });

 

Create a new view and add an iphone. cshtml extension file.

If the user-agent contains the iphone, the page is displayed!

Easy!

 

In addition, on stackoverflow, find another person's statement, basically the same, and directly go to the code.

 1 DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("iPhone") 2 { 3     ContextCondition = context => 4         context.GetOverriddenBrowser().IsMobileDevice 5         && (context.Request.UserAgent.IndexOf("iPhone", StringComparison.OrdinalIgnoreCase) >= 0 6         || context.Request.UserAgent.IndexOf("Android", StringComparison.OrdinalIgnoreCase) >= 0 7         || !context.Request.Browser.IsMobileDevice) 8     }); 9 10 /*  Looks complicated, but renders Home.iPhone.cshtml if the overriding browser is11     mobile or if the "real" browser is on an iPhone or Android. This falls through12     to the next instance Home.Mobile.cshtml for more basic phones like BlackBerry.13 */14 15 DisplayModeProvider.Instance.Modes.Insert(1, new DefaultDisplayMode("Mobile")16 {17     ContextCondition = context =>18         context.GetOverriddenBrowser().IsMobileDevice19 });

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.