http://stackoverflow.com/questions/8060979/in-asp-net-mvc-3-what-is-filtercontext-ischildaction
In view pages, you may often need to inject output of another action into current page - for example, injecting menus. Menu generation may involve lots of business logic (determining rights or users, choosing selected item, etc), so it is not done in the partial view, but in controller.
public class MenuController : Controller
{
[ChildActionOnly]
public ActionResult Menu()
{
MenuViewModel model = GenerateMenu();
return View(model);
}
}
This type of action is called ChildAction, as it cannot(and is not supposed to) be called from outside world(by visiting url). This may only be called by application itself, generally from within the view page.
@Html.Action("Menu", "Menu")
And if you wish(or do not wish) to do some specific stuff when the action being executed is a child action, you inspect filterContext.IsChildAction
property.
private bool IsChildAction(RouteData data)
{
bool isChildAction = false;
if (data != null)
{
isChildAction = data.DataTokens.ContainsKey("ParentActionViewContext");
return isChildAction;
}
else
{
return false;
}
}