开发者

What object property contains the Route Name being used when inside ControllerBase

开发者 https://www.devze.com 2022-12-17 12:11 出处:网络
How do I find the Route Name that is being used when inside of the ControllerBase using it? For example, I have a route like this:

How do I find the Route Name that is being used when inside of the ControllerBase using it?

For example, I have a route like this:

routes.MapRoute("Search", "{controller}.mvc/{action}/{criterion}", new { controller = "", action = "", criterion = "" });

...and in my ControllerBase I need the Objec开发者_Python百科t.Property that contains "Search" or the name of the Route that the ControllerBase is currently using if not search.

Thank you.

-Jessy Houle


This question has come up a number of times in various forms. The short answer is that you can't - the Route name is not stored anywhere in the routing data.

There have been various workarounds proposed for this. See this answer for some code for one implementation of Route name tracking. There are others around as well.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号