mvc 3 sitemap provider- multiple paths pointing to same node

╄→尐↘猪︶ㄣ 提交于 2019-12-21 17:43:48

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/7350567/mvc-3-sitemap-provider-multiple-paths-pointing-to-same-node

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!