When rendering using Menu(), current node isn't indicated

May 16, 2011 at 1:55 PM

I've defined the following site-map:

<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0" enableLocalization="true">
	<mvcSiteMapNode title="HomeMecca" changeFrequency="Always" updatePriority="Normal">
		<mvcSiteMapNode title="Search" controller="Home" action="Index" />
		<mvcSiteMapNode title="Advertise" controller="Advertisement" action="NewRentalAd" />

And I'm rendering it with this command (razor syntax):


But when I view either of these pages, there's no "current" or "selected" class on any of the nodes.

The markup just looks like this:

        <a href="/">Search</a>
        <a href="/Advertisement/NewRentalAd">Advertise</a>

Any ideas why this isn't working?

May 16, 2011 at 2:13 PM

Never mind, found the answer!

After debugging the source for a bit, I realized that the rendering is now defined in DisplayTemplates, and the default ones included in the binary don't have any rendering of the current state,

So I just copied SiteMapNodeModel.ascx into the Views/Shared folder of my main web app, with a modification on the <li> tag:

<li<%= Model.IsCurrentNode ? " class=\"current\"" : "" %>><%=Html.DisplayFor(m => node)%>

And sure enough, it worked!

Credit to the developers - this is really nicely done, because now I have full control over the rendering!