1
votes

I have a MVC project and I'm implementing a breadcrumb with the MVCSiteMapProvider.

My MVC.sitemap is the follow:

<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>

I have added to the _layout view

@Html.MvcSiteMap().SiteMapPath()

I need to preserve the parameters to retrieve the correct item when I return to the parent item. To do this I added to the View action the annotation SiteMapPreserveRouteData:

[SiteMapPreserveRouteData]
public ActionResult View(Guid id)

Now, I can navigate using my breadcrumb.

The problem is that it only works with the first item. When I change the item, the breadcrumb disappears...

Sample: I navigate to the Parent p2 -> Child c1, and after I return to the Index and select the Parent p1, the View page of the parent doesn't show the breadcrumb.

It's not happening if I remove the annotation SiteMapPreserveRouteData, but the breadcrumb lost the id then..

What am I doing worng? Some idea?

Thanks

1

1 Answers

1
votes

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.