Lets say I have a site that has a Layout with navigation. This navigation is built each time a page is requested based on options the user has chosen. This navigation does not really have anything to do with the particular view being presented except that it is required for the Layout. The question is, should this be put in the ViewData or should the Model be required to inherit a NavigationModel?
ViewBag.NavItems = navItems;
or
public abstract class NavigationModel
{
public List<NavItem> NavItems { get; set;}
}
public class HomeModel : NavigationModel
{
}
This sounds like an ideal case to use
Html.RenderActioninside of the view to render the navigation. This would call an action on aNavigationControllerthat would be responsible for rendering the menu directly into the view.Some MVC purists feel that
Html.RenderActionbreaks true MVC architecture; I see it as a way of delegating responsibility to render certain parts of the view that are not the primary responsibility of the “main” view that you’re rendering.