Monday, November 23, 2015

Attribute routing in ASP.NET MVC

You may be familiar with Attribute-based routing in ASP.NET Web API, but you may not know that you have the same capability in ASP.NET MVC!

With the release of ASP.NET MVC, you also have Attribute-based routing available to you in the ASP.NET MVC Framework as well as described here: http://blogs.msdn.com/b/webdev/archive/2013/10/17/attribute-routing-in-asp-net-mvc-5.aspx

However, instead of making your changes to support attribute-based routing in the WebApiConfig.cs file found in the App_Start folder, you instead make your changes to the RouteConfig.cs file also in the App_Start folder.

You then can use Routing attributes in a similar manner as you add routes in ASP.NET Web API such as using Route Prefixes and standard Route conventions.

In earlier releases of ASP.NET MVC, you would have to define an ActionName attribute to distinguish different routes as described here: http://www.codeproject.com/Articles/846403/Can-we-overload-MVC-controller-action-methods-MVC

No comments:

Post a Comment