【问题标题】:I seem to be getting a GUID in the MvcSiteMapProvider Breadcrumb trail, not sure why?我似乎在 MvcSiteMapProvider 面包屑路径中获得了 GUID,不知道为什么?
【发布时间】:2013-08-17 11:34:53
【问题描述】:

我正在使用 MVC3、C#、Razor、mvcSiteMapProvider V4。

我正在使用“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”和“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

有什么可能导致这种情况的想法吗?

谢谢。

【问题讨论】:

    标签: asp.net-mvc-3 mvcsitemapprovider asp.net-mvc-sitemap


    【解决方案1】:

    如果 URL 解析器找不到匹配项,您将获得 URL 的 Guid。在这种情况下抛出异常会导致其他问题(请参阅why does URL resolver throw an exception)。

    但是,如果不查看您的更多配置,我无法确切地告诉您为什么它不匹配。一个线索是我们正在使用 UrlHelper.RouteUrl(string, RouteValueDictionary) 来解析 URL。您可以尝试使用您的路由值和路由名称显式调用它。另外,请参阅source code 了解其他线索。

    我注意到的一件事是,您保留了 Background 的 ClientID 路由参数,而该参数甚至没有在该路由中使用。请记住,保留路由参数只会从当前 HTTP 请求中复制它们,而您的其他节点似乎会忘记它们。

    PreserveRouteParameters 通常用于创建数据编辑页面的 CRUD 操作。如果您希望它看起来“记住”用户的导航路径,那么您需要为站点地图的每个唯一路线值组合添加 1 个节点。

    如果上述方法没有帮助,请创建一个显示问题的小型演示项目,然后将其上传到 GitHub,或者将其压缩并提供下载,然后在 GitHub 使用链接打开一个新问题到演示。

    【讨论】:

    • 谢谢你.. 真的很有帮助。这个 GUID 问题让我摸不着头脑。
    猜你喜欢
    • 1970-01-01
    • 2019-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-16
    • 2023-01-27
    • 1970-01-01
    相关资源
    最近更新 更多