In the MVC default route
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
whenever the index action is accessed, the url is not showing the action name when the "Index" action is accessed.
I would like to get that behaviour on a different controller, which is retrieving data for a single item. I would like the default action to be named "get" and for this action I would like the url not to display the action name, just the controller and the item id.
I thought that a similar route to the one above, like this:
routes.MapRoute(
"item_details",
"item/{action}/{id}",
new { controller = "item", action = "Get" }
);
would do the trick, but it gives me a url like localhost:xxxx/item/Get/152... What am I missing?
A URL action is a hyperlink that points to a web page, file, or other web-based resource outside of Tableau. You can use URL actions to create an email or link to additional information about your data. To customize links based on your data, you can automatically enter field values as parameters in URLs.
Each MVC application has default routing for the default HomeController. We can set custom routing for newly created controller. The RouteConfig. cs file is used to set routing for the application.
Every MVC application must configure (register) at least one route configured by the MVC framework by default. You can register a route in RouteConfig class, which is in RouteConfig. cs under App_Start folder.
Routing in ASP.NET MVC cs file in App_Start Folder, You can define Routes in that file, By default route is: Home controller - Index Method. routes. MapRoute has attributes like name, url and defaults like controller name, action and id (optional).
Try this:
routes.MapRoute(
"item_details",
"item/{id}",
new { controller = "item", action = "Get" }
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With