OK new to MVC. I had asked this question earlier and got an answer but I am wondering if there is a simpler solution.
Say I have a master page with a menu laid out as an
You should pass all relevant information in the Model. Ideally your menu will be rendered as a Partial View by a separate controller method. I have a Navigation controller with actions like MainMenu, FooterMenu, Breadcrumbs, etc that render individual parts.
Your model will be a collection of menu items like:
public class MenuItemModel
{
public MenuItemModel()
{
SubMenu = new List();
}
public string Text { get; set; }
public string Controller { get; set; }
public string Action { get; set; }
public bool Selected { get; set; }
public List SubMenu { get; private set; }
}
Your Controller will create a collection of menu items and pass them to the view with the appropriate item selected. Then the view can be as simple as: