1

我有一个 MVC 项目,我正在使用 MVCSiteMapProvider 实现面包屑。

我的 MVC.sitemap 如下:

<mvcSiteMapNode title="Index" controller="Index" action="Index" key="Index">
    <mvcSiteMapNode title="Parent" controller="Parent" action="View" key="Parent" >
      <mvcSiteMapNode title="Child" controller="Child" action="View" />
    </mvcSiteMapNode>
</mvcSiteMapNode>

我已添加到 _layout 视图

@Html.MvcSiteMap().SiteMapPath()

当我返回父项时,我需要保留参数以检索正确的项。为此,我在 View 操作中添加了注释 SiteMapPreserveRouteData:

[SiteMapPreserveRouteData]
public ActionResult View(Guid id)

现在,我可以使用我的面包屑导航。

问题是它只适用于第一项。当我更改项目时,面包屑消失了......

示例:我导航到 Parent p2 -> Child c1,在我返回 Index 并选择 Parent p1 后,父级的 View 页面不显示面包屑。

如果我删除注释 SiteMapPreserveRouteData 就不会发生这种情况,但是面包屑会丢失 id..

我在做什么?有什么想法?

谢谢

4

1 回答 1

1

The problem is most likely your approach. I don't recommend using SiteMapPreserveRouteData at all - it is brute force and more importantly, the approach taken in its design is flawed.

I have created a post that goes into depth about how to track a user's position in the sitemap - How to Make MvcSiteMapProvider Remember a User’s Position. Understanding the information in that post is key to making breadcrumb trails that don't disappear.

于 2013-08-04T06:25:05.307 回答