开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜