Jessy Houle
Jessy Houle

Reputation: 1921

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 Object.Property that contains "Search" or the name of the Route that the ControllerBase is currently using if not search.

Thank you.

-Jessy Houle

Upvotes: 3

Views: 268

Answers (1)

womp
womp

Reputation: 116977

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.

Upvotes: 2

Related Questions