I am wondering if there are any known issues with adding a ViewUserControl at run time (to a ViewPage). It works fine if I add the control declaritively but not if I add the control programmatically (in the code behind file in this case). I don’t get an error, it just does not render the control but stepping through the debugger does confirm that the relevant methods in the page life cycle are being called.
I do realize that it’s not quite kosher to use a code behind file with ASP.NET MVC but I do have reasons for wanting to do so.
Send the list of controls you want to load and pass it to the view model.
Controller action:
View:
This will keep you out of code behind and still let you dynamically specify in the controller which controls to load in the view.