0

I have two MVC views. The parent view uses Html.RenderAction to render a child view.

How, from within the base controller, can I identify whether the current view is an independent view or, whether it being rendered within a parent view using Html.RenderAction?

Anthony Faull
  • 17,549
  • 5
  • 55
  • 73

2 Answers2

0

Not sure if this will help, but MVC does have an attribute that allows an action method to be called only as a child action.

ChildActionOnly Attribute

Andy T
  • 10,223
  • 5
  • 53
  • 95
0

Use ControllerContext.IsChildAction. This returns true if RenderAction was used.

if (!ControllerContext.IsChildAction) 
{
    // We were called via the URL and not via a [Phil Haack's blog][1]) call.
}

See Phil Haack on MVC2 RenderAction and Action.

Anthony Faull
  • 17,549
  • 5
  • 55
  • 73