I'm using MvcSiteMapProvider
from Github to generate breadcrumbs in my project. I have two places where an action can be called from different controllers, and the breadcrumb has to show the calling controller.
Based on several sources (mvc 3 sitemap provider- multiple paths pointing to same node, MVCSiteMapProvider breadcrumbs incorrect parent node id, MVCSiteMapProvider Dynamic Node always returns the first node for all pages in the breadcrumbs, and external references from those articles), I have switched from using the file Mvc.sitemap
to decorating my actions with MvcSiteMapNodeAttribute
. I have also put the proper settings into my web.config
file.
<add key="MvcSiteMapProvider_IncludeAssembliesForScan" value="Solution.Project" />
<add key="MvcSiteMapProvider_UseExternalDIContainer" value="false" />
<add key="MvcSiteMapProvider_ScanAssembliesForSiteMapNodes" value="true" />
<add key="MvcSiteMapProvider_SecurityTrimmingEnabled" value="true"/>
<add key="MvcSiteMapProvider_EnableSiteMapFile" value="false"/>
However, the breadcrumbs are not recognizing the two paths.
The nodes' attributes are, starting from the root node:
(in controller Home)
[MvcSiteMapNodeAttribute(Title = "Home", Key = "Home")]
(in controller Path1)
[MvcSiteMapNodeAttribute(Title = "Path 1", Key = "Home.Path1", ParentKey = "Home")]
[MvcSiteMapNodeAttribute(Title = "Action", Key = "Home.Path1.Action", ParentKey = "Home.Path1", Route="Home.Path1")]
[MvcSiteMapNodeAttribute(Title = "Action", Key = "Home.Path2.Action", ParentKey = "Home.Path2", Route="Home.Path2")]
(in controller Path2)
[MvcSiteMapNodeAttribute(Title = "Path 2", Key = "Home.Path2", ParentKey = "Home")]
return RedirectToAction("Action", "Path1", new { Route = "Home.Path2" } );
No matter whether I call Action
from Path1
or Path2
, the breadcrumb always reads Home > Path 1 > Action
.
I've been working with a co-worker on this for parts of a few days, and we're at a loss as to why the different keys and the proper routes aren't working as intended.