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?

有帮助吗?

解决方案 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.

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top