This article is part of the Maintainable MVC Series.
Soon – once that MVC 2 is finalized and released – we will have access to the new Html.Action command with which we can easily render partials for shared functionality, like navigation structure or other parts of the master page that need dynamic data. As Phil Haack shows in this post it’s a very powerful and urgently needed feature.
In the master view you will have a call like this:
<%= Html.Action("Menu") %>
This will directly call a method in one of your controllers to supply the partial view with its data:
[ChildActionOnly]
public ActionResult Menu() {
NavigationData navigationData = navigationService.GetNavigationData();
MenuViewModel menuViewModel = mapper.GetMenuViewModel(navigationData);
return PartialView(menuViewModel);
}
Unfortunately in MVC 1 we have to make use of a more elaborate trick to get the data to the partial view.