c# - How to get a route without the action in the URL -
i want route like:
/product/123
i have action don't want in url, currently:
/product/get/123
how this?
global.asax.cs
routeconfig.registerroutes(routetable.routes); public static void registerroutes(routecollection routes) { routes.ignoreroute("{resource}.axd/{*pathinfo}"); routes.maproute( "default", "{controller}/{action}/{id}", new { controller = "home", action = "index", id = urlparameter.optional }, new[] { "myapp.web.controllers" } ); }
you can use route attribute define path this:
[route("product")] public class productcontroller { [route("{productid}"] public actionresult get(int productid) { // code here } }
which provides full route definition "/product/{productid}" "/product/123" in case. more details there: https://blogs.msdn.microsoft.com/webdev/2013/10/17/attribute-routing-in-asp-net-mvc-5/
Comments
Post a Comment