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?

Était-ce utile?

La 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.

Autres conseils

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top