4

i've recently started to use marteenba's sitemap provider, because i couldn't solve a route problem with the other sitemap i had. It's way better than my previous one. My question is: how can i create different breadcrumb trails from pages that go to a single main page? Consider the idea below:

Sitemap Structure

<mvcSiteMapNode title="Home" controller="Home" action="Index" changeFrequency="Always" updatePriority="Normal">
       <mvcSiteMapNode title="Clients Search" controller="ClientBussiness" action="ClientSearch" description="Clients Search">
            <mvcSiteMapNode title="Contract Analysis" controller="Contract" action="Index"/>
        </mvcSiteMapNode>

        <mvcSiteMapNode title="Advanced Search" controller="ClientBussiness" action="AdvancedSearch" description="Clients Advanced Search">
            <mvcSiteMapNode title="Contract Analysis" controller="Contract" action="Index"/>
        </mvcSiteMapNode>

        <mvcSiteMapNode title="Another Search" controller="ClientBussiness" action="AnotherSearch" description="Clients Another Search">
            <mvcSiteMapNode title="Contract Analysis" controller="Contract" action="Index"/>
        </mvcSiteMapNode>
</mvcSiteMapNode>

On the example above, my breadcrumb trail always shows the node Clients Search instead of any other. I don't know if should create different routes for each kind of search (i did this on my last sitemap, but unfortunately iis6 didn't like it).

I appreciate your help.

EDIT

searching on forums i found a similar question. So, consider the structure below:

Home >> Search >> Contracts
Home >> Another Search >> Contracts
Home >> Advanced Search >> Contracts
Home >> Web Service Search >> Extra fields >> Contracts
AdrianoRR
  • 1,131
  • 1
  • 17
  • 36

1 Answers1

5

Well it seems that all i needed to do was to add some dynamic nodes attributes on my controllers. You can read how to do it here. Using the example above, here's how it's done:

 [MvcSiteMapNodeAttribute(Title = "Search", Key = "search", ParentKey = "ContractSearch", Route = "SearchRoute")]
        [MvcSiteMapNodeAttribute(Title = "AdvancedSearch", Key = "ContractAdvSearch", ParentKey = "AdvSearch", Route = "AdvSearchRoute")]
        [MvcSiteMapNodeAttribute(Title = "AnotherSearch", Key = "ContractAnotherSearch", ParentKey = "AnotherSearch", Route = "AnotherSearchRoute")]
        public ActionResult ContractIndex()
{
   //Things to do...         
}

On the example above, each kind of search will be properly defined on the breadcrumb trail. Keep in mind that you have to define different routes for each kind of "search" you want to use. So, if you want to have 3 nodes pointing to the same url, each node must have it's own route and it's key, defined on MvcSiteMapNodeAttribute.

AdrianoRR
  • 1,131
  • 1
  • 17
  • 36
  • I tried what you did but I'm also using a custom attribute [SiteMapPreserveRouteDataForParent] to maintain the previous routes parameters.. and for some reason when I use a route = "whatever" I get a "A route named 'whatever' could not be found in the route collection." Any ideas why that would be happening? – Ryan Sep 19 '11 at 20:31
  • 1
    Well, first thing is to check if you really have a defined route on your global.asax. If it can't find your route it may mean that your route path is wrong - you may have defined your `SiteMapNodeAttribute` with a correct route name but an undefined path. Second, don't forget to check your `Mvc.sitemap` file to see if there's any route conflicts happening. – AdrianoRR Sep 20 '11 at 13:24
  • So the "Route" parameter is to specify the previous route or the current route? – Ryan Sep 20 '11 at 14:30
  • 1
    To specify the current Route. However, don't forget that your sitemap will be built based on the SiteMapAttributeNode or on your Mvc.sitemap. – AdrianoRR Sep 21 '11 at 12:32
  • I am struggling with the same problem. Registering the routes will not work for me, since all nodes are generated dynamically. So I don't know upfront what the routes will be: AA>BB>CC>>item or DD>EE>FF>>item, where item is the same item, but AA, BB, etc. are gerenated dynamically from database with dynamic node generator. – Mounhim Feb 05 '12 at 01:06
  • @AdrianoRR i couldn't make it work. I am using routes with attributes such as MvcSiteMapNode; but no breadcrumb appears. I had tried to use canonicalKey but got an error says: "The 'CanonicalUrl' has already been set. Simultaneous use of both CanonicalUrl and CanonicalKey is not allowed.". Is there any other resource for these situation. – bahadir arslan Oct 30 '14 at 08:22