Introduction
In this article, we will explore Child Action methods accessible at the View level. In general, each public method in a controller class is an action method.
There could be multiple scenarios when we want to display some dynamic information (data) on pages. A Child action is helpful in those scenarios.
A ChildAction method is an action method thought its accessible from the View only, if you invoked this action via an URL then it prompts you an error that we will look down the level in this article.
I have a HomeController in the MVC application that contains code as given below:
- public class HomeController : Controller
- {
- public ActionResult Index()
- {
- ViewBag.TempValue = "Index Action called at HomeController";
- return View();
- }
- [ChildActionOnly]
- public ActionResult ChildAction(string param)
- {
- ViewBag.Message = "Child Action called. " + param;
- return View();
- }
- }
To behave an action as child action it requires decorating with [ChildActionOnly] as shown in the image below:

Initially it is invoking an Index action that in turn returns to Index views and at the View level it calls the ChildAction named “ChildAction”.




Joginder BangerPosted Apr 8, 2018, 10:42 PM
Good job thanks.... Why we can not hit through address which class or interface prevents.
Niranjan PoddarPosted Dec 22, 2017, 12:29 AM
Nice explanation.....Thanks
yogesh bombePosted Jan 4, 2017, 7:35 AM
Can we redirect to different page instead of showing error page of ChildActionOnly attribute
Ravi PatelPosted May 10, 2016, 1:21 AM
nice explanation thanks
shaik peerullaPosted Oct 3, 2015, 2:00 PM
Great article thanks for posting
Sachin KaliaPosted Feb 24, 2015, 10:30 PM
Prakash JoshiA Child Action method is an action method which its accessible from the View only, if you invoked this action via an URL then it prompts you an error..A sceanrio could be like this...You have created a View and in that same view you are using ChildAciton method to call another view..(Demanding View) Try it once..Hope the scenario is clear to you..
Prakash JoshiPosted Feb 24, 2015, 3:15 AM
Hello Sachin Kalia can I use Child Action Method for viewing both Index view and Create View in a same page
Sachin KaliaPosted Aug 13, 2014, 12:40 AM
Thanks @Pradeep
Pradeep ShetPosted Aug 12, 2014, 2:11 PM
good 1
Guest UserPosted Aug 8, 2014, 2:28 AM
thanks Sachin!
Sachin KaliaPosted Aug 8, 2014, 1:15 AM
The main advantage is You have leverage.to call it from View.There is no need to invoked via URl 2.Child Actions are mostly used to render partial pieces in pages like some reused information (widgets).You can call PartialView with hekp of Action and Renderaction method as i described above in [email protected]("ChildAction", "Home", new { param = "first" }) .
Guest UserPosted Aug 7, 2014, 8:40 PM
what is the main advantage of using childaction, and same use case? can you please explain.