MVC 4 :Mobile Routing: Part One


If you have not read Scott Hanselman’s Blog Post  on the developers preview of Visual Studio 2011, Asp.Net and MVC 4. GO READ IT !!

What caught my eye about MVC 4 was its new mobile support.   As mentioned in Scott’s Blog;

ASP.NET MVC 4 Developer Preview is the latest release of our MVC framework. This release includes built-in support for mobile sites, new, fresh HTML5 project templates as well as jQuery Mobile. It has enhanced support for asynchronous methods, and custom code generation.

You can download the bits from here http://www.asp.net/mvc/mvc4

So one of the new is mobile device detection and routing.  In normal MVC you have a controller action that has an associated SINGLE view. The view then has the same filename as the action method. MVC 4 has a feature that allows routing from a  {controller}/{action} to one of several views depending on whether or not the browsing device is mobile.

The MVC 4 Functionality simply adds the identifier mobile between the two names {ActionName}.mobile.{fileType} example “Index.mobile.cshtml” This can be used in the case of _layout pages as well. If a mobile device browses to the site then a view with the .mobile middle name will be returned if it it exists. If not then the desktop view will be returned.

Advertisements

One thought on “MVC 4 :Mobile Routing: Part One

  1. Pingback: MVC 4 Developers Preview : Mobile Routing : Part 2 | Chip Burris

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s