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

相关问题