Get controller name of outer view that called Html.RenderAction?

50 Views Asked by At

Let's say I have these components:

ControllerA (ViewA) 
ControllerB (ViewB)
ControllerX (ViewX)

ViewA and ViewB embed a Html.RenderAction('ControllerX') in them.

I understand that from within ViewX, ViewContext.RouteData.Values["Controller"] will give me "ControllerX"... and that completely makes sense.

What I am wondering is, whether it's possible to get the value of the "outer" controller from within ViewX?

In other words, if I'm in ViewX, is there a way for me to know whether I was rendered from ControllerA or ControllerB?

Reason being is that there are certain aspects within ViewX that I need to have dynamically built based on where it's coming from. I'm pretty sure I can get this desired behavior using partial views and the necessary ViewModels but I like the approach of a self contained Rendered Action.

[Update] Thanks to Stephen, I found the a duplicate question + answer here:

How to get current controller and action from inside Child action?

0

There are 0 best solutions below