Get route name in ASP.NET MVC

I use this code in my view to list the routes, but I cannot get the route names from the Route object.

RouteCollection routes = RouteTable.Routes; foreach (RouteBase rb in routes) {Route route = rb as a route;

So how can I access the name of the route?

+3
source share
1 answer

I also found this solution by Stephen Walter, which allows us to keep the code intact (use the MapRoute method instead of MapRouteWithName, as described in another solution in Stack):

http://stephenwalther.com/blog/archive/2008/08/03/asp-net-mvc-tip-29-build-a-controller-to-debug-your-custom-routes.aspx

+1
source

Source: https://habr.com/ru/post/1724221/


All Articles