0

我使用的是MVC3,C#,Razor,mvcSiteMapProvider V4。我似乎在MvcSiteMapProvider Breadcrumb蹤跡中獲得一個GUID,不知道爲什麼?

我使用 「Mvc.sitemap」

 <mvcSiteMapNode title="Reports" controller="Report" action="Index" preservedRouteParameters="ClientId" route="Report"> 
      <mvcSiteMapNode key="Report_Section" title="Sections" controller="Section" action="FilterByReport" preservedRouteParameters="ClientId,ReportId" route="Report_Section"> 
      <mvcSiteMapNode key="Background" title="Background" controller="Wizard" action="Index" preservedRouteParameters="ClientId,ReportID,SectionID,SectionName" route="Background"/> 

的 「Global.asax中」 定製路線是這樣的:

 routes.MapRoute("Report", "Report/{ClientId}", new { controller = "Report", action = "Index", ClientId = UrlParameter.Optional }); 
     routes.MapRoute("Report_Section", "Report/{ClientId}/Section/{ReportId}", new { controller = "Section", action = "FilterByReport", ReportId = UrlParameter.Optional }); 
     routes.MapRoute("Background", "Report/{ReportID}/SectionID/{SectionID}/SectionName/{SectionName}", new { controller = "Wizard", action = "Index", ReportID = UrlParameter.Optional, SectionID = UrlParameter.Optional, SectionName = UrlParameter.Optional }); 

「報告」 和 「Report_Section」 路線做工精細。但是,當我進入「背景」路線時,我在mvcSiteMap BreadCrumb URL中丟失了「Report_Section」和「Report」路線的所有路線結構。相反,我得到一個GUID即:

http://localhost/7ebe9bb9-a663-43fd-9fb1-865866be12b9 

我相信這可能是自動生成的XML節點密鑰。然而,它點擊後生成404。

我應該得到的東西,如:

報告

http://localhost/Report/10 

http://localhost/Report/10/Section/100 

任何想法可能是造成這個?

謝謝。

回答

1

如果URL解析器無法找到匹配項,您將得到URL的Guid。在這種情況下拋出異常導致其他問題(請參閱why does URL resolver throw an exception)。

但是,我不能確切地告訴你爲什麼它不匹配,而沒有看到更多的配置。一條線索是我們使用UrlHelper.RouteUrl(string,RouteValueDictionary)來解析URL。您可以嘗試使用路由值和路由名稱顯式調用它。另請參閱source code瞭解其他線索。

我注意到的一件事看起來就是,當它在該路線中沒有被使用時,您將爲後臺保留ClientID路由參數。請記住,保留路由參數只會從當前的HTTP請求中複製它們,而其他節點似乎會忘記它們。

PreserveRouteParameters通常用於製作數據編輯頁面的CRUD操作。如果您希望它看起來像「記住」用戶的導航路徑,那麼您需要爲每個唯一路由值組合添加1個節點到您的站點地圖。

如果上述內容不起作用,請創建一個展示該問題的小型演示項目,並將其上傳到GitHub,否則將其壓縮並提供下載,然後在GitHub處打開一個新問題,並鏈接到演示。

+0

感謝這..真的很有幫助。這個GUID問題讓我撓了撓頭。 – SamJolly

相關問題