Calling ASP.NET MVC child action from the controller

842 Views Asked by At

In ASP.NET MVC views, it's possible to call child actions like this:

@Html.Action("ActionName")

That will render the results of the action called ActionName to the output of the view.

Is it possible to make such child action call in the controller?


The output of my controller actions is JSON, not HTML, so I prepare the resulting JSON objects in the controllers instead of the Razor templates. It would be useful if I could use the same mechanism as I use when working with Razor views to render parts of the response by a child action.

I know that there's a possibility of structuring the code differently, so I could reuse the same component in two different controllers. But I want to specifically know if I can get the results of a child action in a controller the same way I can do in the view.

Please see the question comments below as well for more information about the problem.

0

There are 0 best solutions below