Get controller and action name from within controller?

For our web application I need to save the order of the fetched and displayed items depending on the view – or to be precise – the controller and action that generated the view (and the user id of course, but that’s not the point here).

Instead of just giving an identifier myself in each controller action (in order to use it for some view-dependant sorting of DB outputs), I thought that it would be safer and easier to create this identifier automatically from the controller and action method it gets called from.

How can I get the name of the controller and action from within the action method in a controller? Or do I need reflection for that?

13 Answers
13

Leave a Comment