BT

ASP.NET MVC 4 is Live

by Jonathan Allen on Feb 22, 2012 |

The first beta of ASP.NET MVC 4 has recently been released with a “go-live” license. This means that even though the release is not yet complete, Microsoft is confident enough to allow it in production use. Enhancements include improvements to the Razor view engine, asynchronous support, WebSockets, and much more.

Razor View Engine

The default view engine for ASP.NET MVC is getting a couple of new features designed to reduce the amount of boilerplate code needed. HTML attributes starting with ~/ will now be automatically replaced with the application root, developers no longer need to use the Url.Content function. Another big time saver is conditional attributes. If the myClass variable in class="@myClass" is null, the entirely attribute is automatically removed for you.

Note: This feature is shared with ASP.NET Web Pages 2.

CSS and JavaScript Management

MVC 4 highly encourages developers to use bundling and minification to reduce the time it takes to deliver content to the browser. Instead of listing each and every file needed by the client, developers can instead use the ResolveBundleUrl function to capture everything in a given folder. Jon Galloway notes that this is especially helpful when updating common libraries such as jQuery.

Mobile Development

MVC 4 now includes jQuery Mobile in the standard mobile templates. These templates are used to build views that will be accessed via the Display Modes subsystem. While only the default (i.e. desktop) and mobile modes are registered by default, developers are free to add their own modes. Generally these would respond to user agent strings, but in theory you have a lot of flexibility when it comes to this.

Task Support for Asynchronous Controllers

Switching to an asynchronous pattern is so easy with MVC4 and C# 5 it is hard to imagine anyone continuing to write blocking style controller methods. Instead of returning an ActionResult, one simply returns an “async Task<ActionResult>”. Of course the underlying service calls will have to be updated to support await-style calls, but that too is an almost mechanical conversion that can be handed off to an intern or junior developer.

A nice touch for asynchronous controllers is the ability to support cancellation tokens. Instead of blindly aborting the thread, the entire call stack can participate in the process. The actual CancellationToken instance is supplied by the framework, developers just need to forward it to any service calls.

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

That is great news actually by Milco van Klingeren

Great news!, With the automatic detection of mobile devices, the right views is loaded for it. And all together JQuery mobile makes it really easy to write apps (using pages/AJAX).

It's a nice combination.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

1 Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT