tags:

views:

31

answers:

1

Hi Is there a way to retrieve the current routing action from a MVC request?

Cheers,

raj

+3  A: 

In general, all route values are stored in RouteData. If you want to know it in a view, you use:

<%= Html.ViewContext.RouteData.Values["action"] %>

If you are in a controller, you use:

string action = RouteData.Values["action"];

Am I answering your question?

Jan Zich
But... Wouldn't you know what action has been requested inside a controller action? It's the action that is being executed.
Robert Koritnik
Yes, of course :-) I wanted to originally mention it, but there could be a legitimate reason for it. For instance, an action can call some generic infrastructure utility function which may need to inspect it.
Jan Zich