1

我目前正在使用 MVCSiteMapProvider 为我的网站生成面包屑。我通过在 SiteMapTitle 属性中传递 viewData 值来创建站点地图标题。当我第一次访问链接时,它会根据需要创建面包屑,但是当我尝试重新访问我网站上的任何其他链接时,它会显示标题的 Viewdata 的第一次访问值。代码看起来像这样

[SiteMapPreserveRouteData] 
    [SiteMapTitle("atlas")]
    public ActionResult Index(string id ,string Atlas)
    {
        if (!string.IsNullOrEmpty(Atlas))
        {
            ViewData["atlas"] = Atlas;
        }
        Taxonomy taxonomy = db.GetTaxonomy(new Guid(ConfigurationManager.AppSettings["TherapyId"]));

        var atlasList = taxonomy.GetTerms(id, 2);

        return View(atlasList);
    }

站点地图看起来像这样

<mvcSiteMapNode title="Home" controller="Home" action="Index" changeFrequency="Always" updatePriority="Normal" >

<mvcSiteMapNode title="Therapy"  controller="Therapy" action="Index"  >
  <mvcSiteMapNode title=""  controller="Atlas" action="Index" >
    <mvcSiteMapNode title=""  controller="Specialties" action="Index">
      <mvcSiteMapNode title=""  controller="Specialties" action="ViewImage"  />      
    </mvcSiteMapNode>        
  </mvcSiteMapNode>
</mvcSiteMapNode>

任何帮助将不胜感激

4

2 回答 2

0

这可能是因为提供者实现了缓存。您可以尝试将 cacheduration(在 web.config 中)设置为 0,以禁用缓存,但这会对性能产生很大影响。

于 2012-06-11T21:22:54.457 回答
0

您应该升级到 MvcSiteMapProvider v4。这是一个缓存错误,现已修复。此外,您不应使用 SiteMapPreserveRouteDataAttribute,因为它现在已被弃用。为了保留路由值,您应该在 ISiteMapNode 对象上使用preservedRouteParameters。

有关如何使用preservedRouteParameters 的示例,请参阅标题为如何使MvcSiteMapProvider 记住用户位置的博客文章。

于 2013-10-30T09:06:42.560 回答