ASP.NET MVC 4.0 Mobile Template
Join the DZone community and get the full member experience.Join For Free
Microsoft has released the much awaited ASP.NET MVC 4.0 developer preview and there are lots of features bundled with it. One of the greatest features is the ability to build mobile websites. So let’s create a simple application and let’s see how it works.
To create mobile site first you need to click File->New Project->ASP.NET MVC 4.0 Web application. Like following.
Now once you click OK it will open a new another dialog like following where we have to choose the Mobile site.
As you can see in above post I have selected Razor view Once you click it will create a new application like following. As you can see similar structure as normal MVC Application application below.
This view are based on the standard jQuery Mobile. So this can be viewed in any tablet or mobile device. So if you have IPad and IPhone both then it will work on both. You need not to different application for both. see the browser first I have selected standard IPad size of browser.
Now lets see how it look in mobile. So I have made my browser same site as mobile. As you can see its working in both.
If you see the code of view you can see the razor syntax over there. Nothing change in razor syntax. But as you can see in below code you need to use Jquery mobile attributes like data-Role and other stuff which will convert standard HTML into mobile or device compatible website.
<ul data-role="listview" data-inset="true"> <li data-role="list-divider">Navigation</li> <li>@Html.ActionLink("About", "About", "Home")</li> <li>@Html.ActionLink("Contact", "Contact", "Home")</li> </ul>
That's it. It’s very easy you can create mobile compatible site in few hours.
Published at DZone with permission of Jalpesh Vadgama, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.