Given you have:
ControllerA
ControllerB
And in the view for ControllerA you invoke:
@Html.Action("ControllerB", "Home");
In the ‘Home’ action in ControllerB, how can you determine what the originally invoked action & controller were?
I know I can determine the URL from the http context, but for the life of me I cannot figure out how to use this to map back to the originally invoked controller and action.
Nb. The solution I’m looking for must be arbitrary depth. If ControllerB invokes Html.Action on ControllerC which invokes Html.Action on ControllerD, I need to be able to resolve that the original action was ControllerA::Home from ControllerD::Home.
Use the
ControllerContext.IsChildActionproperty to determine if you are in a child action, then theControllerContext.ParentActionViewContextproperty contains all the information you need. This has aRouteDataproperty which can give you the controller and action name.