MVC SiteMap gives wrong node

Oct 11, 2010 at 3:57 PM

I have a site with 4 sections and each section have a numerous of products.

Each product leads to same View {ViewProduct}

Let's assume that we have the following structure

  • Section 1
    • Product 1
    • Product 2
  • Section 2
    • Product 3
    • Product 4
  • Section 3
    • Product 5
    • Product 6
  • Section 4
    • Product 7
    • Product 8

If I navigate to Product 1 the Mvc SiteMap breadcrumb return Section 1->Product 1

But if I navigate to product 2 which is assigned to Section 2, the breadcrumb returns Section 1->Product 2.

The same is happened for all the other sections except the first in the list.

This is the SiteMap.Xml

<mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-2.0" enableLocalization="true">
    <mvcSiteMapNode title="Home" controller="Home" action="Index">
        <mvcSiteMapNode title="Section 1" controller="Products" action="ForTrade" url="/products/ForTrade">
            <mvcSiteMapNode controller="Products" action="ViewProduct"/>
        </mvcSiteMapNode>
        <mvcSiteMapNode title="Section 2" controller="Products" action="ForSale" url="/products/ForSale">
            <mvcSiteMapNode controller="Products" action="ViewProduct"/>
        </mvcSiteMapNode>
        <mvcSiteMapNode title="Section 3" controller="Products" action="UserGifts">
            <mvcSiteMapNode controller="Products" action="ViewProduct"/>
        </mvcSiteMapNode>
        <mvcSiteMapNode title="Section 4" controller="Products" action="ForSeek">
            <mvcSiteMapNode controller="Products" action="ViewProduct"/>
        </mvcSiteMapNode>
    </mvcSiteMapNode>
</mvcSiteMap>

How could I solve this issue?
Thanks

Oct 12, 2010 at 10:50 AM

MvcSiteMapProvider will have no clue in which of the products nodes it is unless you tell it that product 2 is part of section 2. This can be done by using dynamic sitemaps (check http://mvcsitemap.codeplex.com/wikipage?title=Dynamic%20sitemaps&referringTitle=Home)

Oct 12, 2010 at 11:12 AM

Thanks for reply maartenba

I'll try it out