Tuesday, June 5, 2012

ASP.NET MVC 4 and mobile web

Here is how to set up for mobile web on MVC 4 (or at least my preferred way) follow instructions here:

Note the comment from Chip below the article, there is a Last-In-First-Out principle for the order of specifying the order of devices. So instead of the order used in the article, use Chip's.

Also note that the examples are for MVC 4 developer preview, the correct way in MVC 4 beta is 
  • DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("mobile")
instead of
  • DisplayModes.Modes.Insert(0, new DefaultDisplayMode("mobile")


So updating and combining the info, this is the correct way in global.asax:



DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("mobile") {
          ContextCondition = Context => Context.Request.Browser.IsMobileDevice
});


DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("Tablet"){
          ContextCondition = Context => [how to id tablet]

});

DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("AndroidTablet"){
         ContextCondition = Context => [how to id android tablet]

});


)

No comments:

Post a Comment