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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -