Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is an MVC child action?

Tags:

asp.net-mvc

I read about child actions in MVC (fundamental book), but I don't really know what it is?

Could some one please explain these methods?

like image 575
Shahrooz Jafari Avatar asked Sep 21 '12 11:09

Shahrooz Jafari


People also ask

What are non action methods in MVC?

Non-Action is another built-in attribute which indicates that a public method of a Controller is not an action method. It is used when we don't want that method to be treated as an action method. Please read my previous articles to learn more about Selectors in ASP.NET MVC.

What does ASP action mean?

The asp-action attribute value represents the controller action name included in the generated href attribute. The following markup sets the generated href attribute value to the speaker evaluations page: CSHTML Copy.


1 Answers

Phil Haack explains it nicely in this blog post. Basically a child action is a controller action that you could invoke from the view using the Html.Action helper:

@Html.Action("SomeActionName", "SomeController") 

This action will then execute and render its output at the specified location in the view. The difference with a Partial is that a partial only includes the specified markup, there's no other action executing than the main action.

So you basically have the main action which received the request and rendered a view, but from within this view you could render multiple child actions which will go through their independent MVC lifecycle and eventually render the output. And all this will happen in the context of a single HTTP request.

Child actions are useful for creating entire reusable widgets which could be embedded into your views and which go through their independent MVC lifecycle.

like image 98
Darin Dimitrov Avatar answered Sep 19 '22 01:09

Darin Dimitrov