MVC: How to get controller to render partial view initiated from the view
You should use: @Html.RenderAction
or @Html.Action
.
Thanks to Stephen Muecke and Erick Cortorreal I got it to work.
This is what the controller should look like:
[ChildActionOnly]
public PartialViewResult GetMenu()
{
MenuStructuredModel menuStructuredModel = menuBusiness.GetStructuredMenu();
return PartialView("~/Views/Shared/MenuPartial", menuStructuredModel);
}
And it may called like:
@Html.Action("GetMenu", "Home")
(Hence GetMenu()
is declared in the HomeController
in my example).
The controller is now called (and the model is populated) prior to the partial view is rendered.