What is Child action and how to invoke it?

Child actions are useful for creating reusable widgets which could be embedded into your views. In ASP.NET MVC partial views are used to create reusable widgets and a partial can be render by an action method. This action method can has child attribute and has its independent MVC lifecycle from parent view. Also, an action which has child attribute cannot be called independently. It always will be called within a parent view otherwise it would give error.

[ChildActionOnly]
public ActionResult MenuBar()
{
  //TODO:
  return PartialView();
}

A child action is invoked by using @Html.RenderAction or @Html.Action helper methods from inside of a view.

Tagged , . Bookmark the permalink.

Leave a Reply