How do I get Route name from RouteData?

前端 未结 10 891
猫巷女王i
猫巷女王i 2021-02-05 02:03

I have several routes defined in my Global.asax;

When I\'m on a page I need to figure out what is the route name of the current route, because route name drives my site

10条回答
  •  梦毁少年i
    2021-02-05 02:43

    I have been facing the same dilemma, and I came to the conclusion that unfortunately, there doesn't seem to be a way to find out which route (by its name) the ASP.NET has picked for usage.

    It seems you can only figure that out by the names of the parameters that might exist in your route - those will show up in the RouteData.Values dictionary.

    If someone knows a way to somehow get at the actual name of the route picked by ASP.NET for a given URL, I'd be interested to know how to do that myself, too!

提交回复
热议问题