Question

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?

Was it helpful?

Solution 2

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top