Reference: http://www.cnblogs.com/dunitian/p/5218140.html
Simple point, directly on the usage
Create a new MVC project and add the following code to the Golbal.asax
1 // Add a custom suffix 2 DisplayModeProvider.Instance.Modes.Insert (0new defaultdisplaymode ("iphone " )3{4 contextcondition = (Context) = = Context.Request.UserAgent.Contains ("iphone")5 });
Create a new view to add a file with the suffix iphone.cshtml
Then if the iphone is included in the User-agent, the page will open!
It's simple!
In addition, found on the StackOverflow another person's writing, basically the same, directly on the code
1DisplayModeProvider.Instance.Modes.Insert (0,NewDefaultdisplaymode ("IPhone")2 {3Contextcondition = Context =4 context. Getoverriddenbrowser (). IsMobileDevice5&& (context. Request.UserAgent.IndexOf ("IPhone", StringComparison.OrdinalIgnoreCase) >=06|| Context. Request.UserAgent.IndexOf ("Android", StringComparison.OrdinalIgnoreCase) >=07|| !context. Request.Browser.IsMobileDevice)8 });9 Ten /*Looks complicated, but renders Home.iPhone.cshtml if the overriding browser is One Mobile or if the "real" browser is on an iPhone or Android. This falls through A To the next instance Home.Mobile.cshtml for more basic phones like BlackBerry. - */ - theDisplayModeProvider.Instance.Modes.Insert (1,NewDefaultdisplaymode ("Mobile") - { -Contextcondition = Context = - context. Getoverriddenbrowser (). IsMobileDevice +});
MVC View Presentation Mode's mobile layout