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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -