2

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?

Community
  • 1
  • 1
dispake
  • 3,259
  • 2
  • 19
  • 22
  • 1
    If I understand correctly, you want `ViewContext.ParentActionViewContext.RouteData.Values["Controller"]` –  Sep 13 '15 at 08:38
  • Perfect! I did a search with what you provided and found a duplicate answer. Thanks for the guidance. Feel free to submit as answer and I'll award the acceptance. – dispake Sep 14 '15 at 00:55

0 Answers0