Child Action Only
- A controller is a collection of action methods.
- Action methods are just like methods and have a public access specifier.
- Since they are public we can easily call them from a URL request directly from the browser.
- In our projects, when we want an action method to not be called from a URL request we should make the method a child action method.
- An action method can be a child or a normal action method, but child actions are action methods invoked from within a view, you cannot invoke a child action method via user request (URL).
- We can annotate an action method with the [ChildActionOnly] attribute to create a child action. Normally we use child action methods with partial views.
- Thus [ChildActionOnly] is an attribute when it is preceded over any controller action method. After this, the method could not make a request from the browser, it can only be called from a View.
- We can call a child action method by using the following two HTML controls.
Now, accessing this Child action method from the browser request will throw the following error.
Thus from this we conclude that a child action method cannot be called directly from a browser request.
Now the question is, how and from where to call a child action method. We can call a child action method from the view.
So, we need to create a view for consuming this child action method as in the following:
When defining the @Html.Action() method the first parameter should be your child action name.

As in the preceding code, the child action method is “Display”.
Now for my second parameter, I will pass a name so that it will be consumed and displayed using the child action method.

Now I will explain another example, but now accessing using the @html.RenderAction().
Here is the sum child action method with the same controller.
And this is my view using @html.RenderAction().
And my output is:
In this way we can implement Child action methods in our projects.

Shiv Ratan KumarPosted Aug 15, 2018, 11:59 AM
Can we call through JSON
satya maheshPosted Jul 21, 2018, 9:45 AM
Thanks and very nice explanation
Santhakumar MunuswamyPosted May 25, 2015, 2:51 PM
Thanks for sharing
Khargesh RajputPosted May 25, 2015, 5:53 AM
thnx for sharing this