Copy and paste from What's New in MVC4 - MVC3 Vs MVC4
What's New in MVC4 - MVC3 Vs MVC4
Default project template enhancements
The template used to create new ASP.NET MVC 4 projects has been updated to create a more modern website.
Mobile Project Template
If you are starting a new project and want to create a site specifically for mobile and tablet browsers, you can use the new Mobile Application project template. It is based on jQuery Mobile, an open source library for creating a touch optimized user interface
Display modes
The new "Display Modes" feature allows the application to select views depending on the browser making the request. For example, if the desktop browser requests the main page, the application may use the Views\Home\Index.cshtml . If the mobile browser requests the main page, the application may return the Views\Home\Index.mobile.cshtml .
DisplayModes.Modes.Insert(0, new DefaultDisplayMode("iPhone") { ContextCondition = (context => context.Request.UserAgent.IndexOf ("iPhone", StringComparison.OrdinalIgnoreCase) >= 0) });
jQuery Mobile, browse switch and browser browser
jQuery Mobile is an open source library for building a web interface with an optimized touch interface. If you want to use jQuery Mobile with ASP.NET MVC 4, you can download and install the NuGet package to get you started. To install it from the Visual Studio Package Manager console, enter the following command: Install-Package jQuery.Mobile.MVC This installs jQuery Mobile and some supporting files, including: Views / Shared / Layout.Mobile.cshtml, which is a jQuery layout Mobile A view-switcher component that consists of a partial view Views / Shared / ViewSwitcher.cshtml and a ViewSwitcherController.cs controller. After installing the package, launch the application using a mobile browser (or its equivalent, for example, an add-on for the User Agent User Manager switch). You will see that your pages look completely different because jQuery Mobile handles layout and style. To take advantage of this, you can do the following: If visitors click on a link, theyre switched to the desktop version of the same page. Since your default desktop layout will not include a view switch, visitors will have no way to switch to mobile mode. To enable this, add the following link: _ViewSwitcher for your desktop, only inside the element:
@Html.Partial("_ViewSwitcher")
... Browser redefinition is the main feature of ASP.NET MVC 4 and is accessible even if you do not install jQuery.Mobile.MVC package. However, it only affects the choice of view, layout, and partial view β it does not affect another ASP.NET function, which depends on the Request.Browser object.
Recipes for generating code in Visual Studio
The new Recipes feature allows Visual Studio to generate solution-specific code based on packages that can be installed using NuGet. The Recipes framework allows developers to write plug-ins for code generation, which you can also use to replace the built-in code generators for Add Area, Add Controller and Add View. Because recipes are deployed as NuGet packages, they can be easily checked in the source control and shared automatically for all developers in the project. They are also available for every solution.
Task support for asynchronous controllers
Now you can write asynchronous action methods as single methods that return an object of type Task or Task.
For example, if you are using Visual C # 5 (or using Async CTP), you can create an asynchronous action method that looks like this:
public async Task Index(string city) { var newsService = new NewsService(); var sportsService = new SportsService(); return View("Common", new PortalViewModel { NewsHeadlines = await newsService.GetHeadlinesAsync(), SportsScores = await sportsService.GetScoresAsync() }); }
In the previous action method, calls to newsService.GetHeadlinesAsync and sportsService.GetScoresAsync are called asynchronously and do not block the thread from the thread pool.
Asynchronous action methods that return Task instances can also support timeouts. To have your action method canceled, add a parameter of type CancellationToken to the signature of the action method. The following example shows an asynchronous action method that has a wait time of 2500 milliseconds and displays a TimedOut view to the client if a timeout occurs.
[AsyncTimeout(2500)] [HandleError(ExceptionType = typeof(TaskCanceledException), View = "TimedOut")] public async Task Index(string city, CancellationToken cancellationToken) { var newsService = new NewsService(); var sportsService = new SportsService(); return View("Common", new PortalViewModel { NewsHeadlines = await newsService.GetHeadlinesAsync(cancellationToken), SportsScores = await sportsService.GetScoresAsync(cancellationToken) }); }
Hope this helps. Thanks