c# - ASP.NET MVC Create dynamic navigation sub-menu on the master page -


I am trying to create an asp.net mvc master page so that the site navigation will look like this:

Main menu: Home | About | News
sub menu: Home_Page1 | Home_page2

The sub-menu should always show for the main menu page currently selected in the sub menu section (the 'Home' page is selected on the above example) until a user clicks the mouse Any other main menu items (instead it shows the sub-menu item)

What is the best way to achieve such functionality in ASP.NET MVC?

If you create a menu using an HtmlHelper extension method:

 < Code> & lt;% = Html.RenderMenu ()%>  

You can use the HtmlHelper instance to see the context of the request and can determine which page you are on once you can see it (database, configuration , Where ever your menu data is ...) which is the submenu to present.

There is something to give you that direction that I think you are looking for:

public static MvcHtmlString RenderMenu (this HtmlHelper html) {var somePage = HTML ViewContext.HttpContext.Request.RawUrl; Var menu = Lookup menued onpage (some pages); Return MvcHtmlString.Create (menu.Render ()); }

Comments