Q:

asp.net mvc: Dynamically add child/sub controllers from a controller

In asp.net mvc, you can easily call/add a controller from a view, but what is the easiest way to add child/subcontrollers from a controller.  What Im getting at is I want to dynamically build a list of child controllers from within the controller itself, not from the view.
The pattern I have in mind is derived from the old ibuyspy portal/dnn where you come up with a list of pluggable modules that you want to inject into the page. Each module is, itself, a controller, and is ignorant that it is a child request. But, dnn uses the ui/views to inject the modules, as where I want to create a list of modules in the controller, then tell the view to inject them.
Thanks in advance,
Jesse

A:

If you have an array of objects in your view model that contains information corresponding to the desired modules, you can inject them into the view using RenderAction like this:
<div id="LeftColumn">
    <% foreach (module in Model.Modules) { 
        Html.RenderAction(module.ActionName, module.ControllerName, new {id = module.id}); 
    } %>
</div>

RenderAction is a method that calls a method on a controller, and injects the result into the page at the location where RenderAction is called.  It is part of the ASP.NET MVC Futures assembly.

