【发布时间】:2014-04-18 16:42:43
【问题描述】:
我正在使用来自 Github 的 MvcSiteMapProvider 在我的项目中生成面包屑。我有两个地方可以从不同的控制器调用动作,并且面包屑必须显示调用控制器。
基于多个来源(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 以及这些文章的外部引用),我已从使用文件 Mvc.sitemap 切换到使用 MvcSiteMapNodeAttribute 装饰我的操作。我还将正确的设置放入我的web.config 文件中。
<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"/>
但是,面包屑无法识别这两条路径。
节点的属性是,从根节点开始:
(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" } );
无论我从Path1 还是Path2 调用Action,面包屑总是显示Home > Path 1 > Action。
几天来,我一直在与一位同事合作,但我们不知道为什么不同的键和正确的路线没有按预期工作。
【问题讨论】:
标签: asp.net-mvc-4 breadcrumbs mvcsitemapprovider