[ASP.NET MVC 4] What’s New

IMHP, MVC 3 was a nice enhancement from the previous versions of MVC. Especially, the “Razor” syntax  became the corner stone of ASP.NET MVC programming.

MVC evolves so fast and it is hard to keep up with the changes. What’s new in MVC 4 then?

1. Focus of ASP.NET MVC 4

The main focus of MVC 4 is to make mobile web application development easier.

MVC 4 provides the better support for

  • Mobile
  • HTML5
  • Cloud


2. New Features in MVC 4

The new features of MVC 4 are:

  • New Project Templates
  • Task based Async Controllers
  • Bundling

Also there are some minor changes:

  • New Attributes
  • New HtmlHelper Extension Methods
  • New UrlHelper Extension Methods
  • New Controller Properties


3. Mobile Web Application Development

A new mobile application project template includes the following features

  • View Switcher
  • jQuery Mobile (NuGet  Package)
  • HTML5-based framework
  • Compatibility with popular mobile devices (Windows phone, iphone, and Android)


4. New Project Templates

  • HTML5
  • New Look (jQuery UI)
  • Knockout JavaScript library


5. Task based Async Controllers

Now you can create the “Async” controllers. The action method returns “Task<ActionResult>“.

public async Task<ViewResult> DoSomething()
  SomeService svc = new SomeService();
  return View(await svc.DoAsync());


6. Bundling

// Global.asax


7. Attributes

At first, the [AllowAnonymous] attribute is added. It specifies that actions and controllers are skipped by [Authorize] attribute during authorization.

Also new HTTP method attributes are added.

  • HttpHeadAttribute 
  • HttpOptionsAttribute 
  • HttpPatchAttribute


8. HtmlHelper Extension Methods

At first, the “DisplayName()” method is added. In MVC 3, you need to hard code the display name of the field.

Html.DisplayName(string expression);
Html.DisplayNameFor(Expression<Func<TModel, TValue>> expression);

Secondly, the “TextBox()” and “TextBoxFor()” methods include an additional “format” parameter. It uses the “String.Format()” method to render the value.


9. UrlHelper Extension Methods

public string HttpRouteUrl(string routeName, object routeValues);
public string HttpRouteUrl(string routeName, RouteValueDictionary routeValues);

These new methods are used to generate URLs for Web Api routes.


10. New Controller Properties

public AsyncManager AsyncManager { get; }
protected virtual bool DisableAsyncSupport { get; }
public ProfileBase Profile { get; } // shortcut to HttpContext.Profile
public ViewEngineCollection ViewEngineCollection { get; set; } // shortcut to ViewEngines.Engines

In MVC4, all controllers support asynchronous actions by default. You can disable this behavior using the “DisableAsyncSupport” property (Derived classes can override the flag and set to true).


11. Web API

Web API is introduced with MVC4 but actually it is not a part of MVC.


12. Bundling

In MVC 4, you can bundle a list of style or script files as a single resource using the classes in the “System.Web.Optimization” namespace.

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s