1

在过去的几个小时里,这一直让我发疯。我正在使用 MVC Sitemap Provider 添加面包屑功能。

让我完成我所做的步骤,以便尽可能清楚地说明这一点

  • 从 Nuget 下载资源
  • 然后我的站点地图中有以下内容

    <?xml version="1.0" encoding="utf-8" ?>
    

    <mvcSiteMapNode title="Vehicles" controller="Vehicles" area="Vehicles" action="Index">
      <mvcSiteMapNode title="VehicleName" controller="Vehicles" area="Vehicles" action="Showroom" >
        <mvcSiteMapNode title="Overview" area="Vehicles" controller="Vehicles" action="Overview" />
      </mvcSiteMapNode>
    </mvcSiteMapNode>
    

  • 我认为这是

    @Html.MvcSiteMap().SiteMapPath()

  • 我的第一个问题是:如何用我的实际 VehicleName 替换“VehicleName” for action Showroom?

  • 我的实际问题是:我的 id 没有保留给父母。例如,我的 url 将是 localhost:44357/Vehicles/Overview/Soul/1,而父 url 将是 localhost:44357/Vehicles/Showroom,而不是 localhost:44357/Vehicles/Showroom/Soul/1。url 中的车辆名称是可选的,因此 url 可以是 localhost:44357/Vehicles/Showroom/1。

我希望这是有道理的

谢谢你的帮助。

4

1 回答 1

1

对于问题1:在父节点上设置VehicleName。例如:((MvcSiteMapNode)SiteMap.CurrentNode.Parent).RouteValues.Add("VehicleName", "SomeVehicle");。一个不错的选择也可能是使用动态节点提供程序来创建您的站点地图结构。

对于问题 2: [SiteMapPreserveRouteData] 应该可以解决问题

于 2011-05-30T13:40:26.700 回答