ASP.NET MVC 4 is Live
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.
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.
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.
Juergen Hoeller Jul 22, 2014