BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News New Features for ASP.NET 5 and MVC 6

New Features for ASP.NET 5 and MVC 6

While most of the buzz has been about ASP.NET 5 and the cross-platform execution engine, MVC, Microsoft’s preferred UI and web service framework, is also seeing many changes. The most important being the unification of MVC, Web API, and Web Pages.

It almost goes without saying that Razor, the default rendering engine for MVC 6, will but upgraded to support C# 6. But that’s not the only new feature for Razor.

There are times when it is preferable to embed some JSON data right in the webpage rather than paying for a separate call to the server. This used to involve some tedious mapping code to run the data objects through a JSON converter and expose the result via the view model. In MVC 6, all of that boilerplate has been reduced to just “@Json.Serialize(Model)”.

Another place where boilerplate code has been a problem is image caching. Caching the image is easy, but finding ways to signal to the browser that the cache is no longer valid tends to involve tedious workarounds. With the image tag helper, that becomes as simple as setting the asp-file-version attribute to true. This will cause MVC to “to automatically append image filenames with a cache-buster version number”.

The tag helper framework has also seen some improvements. You can now “bind server side attributes to dictionary properties on your tag helpers”. Tag helpers can also be conditionally activated by the presence of server-side attributes. For more information on writing your own tag helpers, see Jeff Fritz’s article, Get Started with ASP.NET MVC TagHelpers.

Route tokens allow you to write expressions such as “[Route("Products/[action]")” at the class level. With MVC 6, the same tokens can be used in the route name, which can be helpful for diagnostic purposes.

Rate this Article

Adoption
Style

BT