Pregunta

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?

¿Fue útil?

Solución 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.

Otros consejos

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top