Currently I have a page with navigation menu. This navigation menu get it items and sub items from database.
I think that it would be easier for me to control it if I make it as a separate controller.
For example:
public class NavigationMenu : Controller
{
public ActionResult Menu()
{
Model model = // Get items and sub items
return View(model);
}
}
Is this right way to make this or I shouldn’t do this from some reason?
And if I make it this Menu view will not have any master layout. Should I remove all <html><head><body>... html code from it or not?
We use this pattern, though we call it NavigationController, and the action method is TopTabs. We have it as a [ChildActionOnly], and return a partial view. To render the navigation in the layout, we use @Html.Action().
I’d answer your question with a yes, and render the partial view as a child action in either your layout or your main views: