2011-09-08 30 views
4

我最近開始使用marteenba的sitemap provider,因爲我無法解決我的其他站點地圖的路由問題。這比我以前的更好。我的問題是:我如何從頁面創建不同的麪包屑路徑到單個主頁面?考慮下面的想法:mvc 3 sitemap provider-指向同一節點的多條路徑

網站地圖結構

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

在上面的例子中,我的麪包屑總是顯示節點客戶端搜索,而不是任何其他。我不知道是否應該爲每種搜索創建不同的路線(我在我的最後一個網站地圖上做了這個,但不幸的是iis6不喜歡它)。

我感謝您的幫助。

編輯

在論壇上搜索我發現了類似的問題。因此,可以考慮以下結構:

Home >> Search >> Contracts 
Home >> Another Search >> Contracts 
Home >> Advanced Search >> Contracts 
Home >> Web Service Search >> Extra fields >> Contracts 

回答

5

那麼它似乎所有我需要做的就是增加一些動態節點的屬性我控制器。你可以閱讀如何去做here。使用上面的示例,以下是它的完成方式:

[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...   
} 

在上面的示例中,每種搜索都將在breadcrumb蹤跡上正確定義。 請記住,您必須爲要使用的每種「搜索」類型定義不同的路線。所以,如果你想讓3個節點指向同一個url,每個節點必須有它自己的路由,它的關鍵是在MvcSiteMapNodeAttribute上定義的。

+0

我試過你所做的,但我也使用自定義屬性[SiteMapPreserveRouteDataForParent]來維護以前的路由參數..由於某種原因,當我使用route =「whatever」時,我得到了「A route named'whatever '在路線集合中找不到'。「任何想法爲什麼會發生? – Ryan

+1

那麼,首先要檢查你的global.asax是否有確定的路由。如果找不到路線,則可能意味着您的路線路徑錯誤 - 您可能已使用正確的路線名稱定義了您的「SiteMapNodeAttribute」,但路徑未定義。其次,不要忘記檢查你的'Mvc.sitemap'文件,看看是否有路線衝突發生。 – AdrianoRR

+0

那麼「Route」參數是指定以前的路線還是當前的路線? – Ryan