In my MVC3 project, I have installed Maartenba's MvcSiteMapProvider v.3.2.1 and I have a very simple, static, two-level menu that I have created. Below is the conceptual map structure.
- Home
- Member Center
- Member Listing [SELECTED]
- Event Calendar
- Documents
- Administration
Now, there are many sub-pages under Member Listing (e.g. Detail, Edit, etc.), but I don't want these displayed as 3rd level menu items (mainly because they are tied to a specific member ID). However, I do want all these third level pages to be "tied" to the Member Listing menu node so that it shows as selected when on these pages.
I have the following code in my Mvc.SiteMap file:
<mvcSiteMapNode title="Home" controller="Home" action="Index">
<mvcSiteMapNode title="Member Center" area="Members" controller="Home" action="Index" roles="Approved Member" >
<mvcSiteMapNode title="Member Listing" area="Members" controller="Member" action="List" />
<mvcSiteMapNode title="Event Calendar" area="Members" controller="Event" action="List" />
<mvcSiteMapNode title="Documents" area="Members" controller="Document" action="List" />
</mvcSiteMapNode>
<mvcSiteMapNode title="Administration" area="Admin" controller="Home" action="Index" roles="Site Administrator" >
</mvcSiteMapNode>
</mvcSiteMapNode>
To render the menu, I am using the following code in my _Layout.cshtml file:
@Html.MvcSiteMap().Menu(1, true, true, 1, true, true)
Finally, I modified the SiteMapNodeModel.cshtml file so that it adds a "selectedMenuItem" class to the node that correlates to the page the user is viewing. Here's the snippit that renders the menu node.
@model SiteMapNodeModel
<a href="@Model.Url" class="@(Model.IsCurrentNode ? "selectedMenuItem" : "")">@Model.Title</a>
The display and navigation of the map works just fine, until I navigate further into the members area. For example, if I go past Members/Member/List
(which displays the menu correctly) and to a page like Members/Member/Detail/1
, the child nodes under Member Center ("Member Listing", "Event Calendar", etc.) disappear. Therefore, here are my two issues that I have with my current code:
I want to specify that any given page is part of the "Member Center" parent menu node, so that the child menu nodes of "Member Center" will be displayed, regardless of whether the given page is defined as a specific node in the menu structure.
I want to specify (possibly in the view or controller action) that a specific page should be tied to a specific menu node. For example, when the user is at
Members/Member/Detail/1
, I simply want the "Member Listing" child node to be specified asIsCurrentNode
so that the SiteMapNodeModel.cshtml file properly decorates it with the "selectedMenuItem" class.
Any suggestions?