MVC站点地​​图提供程序持久参数

时间:2011-04-06 11:03:44

标签: asp.net-mvc-3 c#-4.0 mvcsitemapprovider

这让我在过去几个小时里疯狂了。我正在使用MVC Sitemap Provider添加breadcrumb功能。

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

  • 从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”作为动作陈列室?

  • 我的实际问题是:我的ID没有持久保存到父级。例如,我的网址是localhost:44357 / Vehicles / Overview / Soul / 1,父网址将是localhost:44357 / Vehicles / Showroom,而不是localhost:44357 / Vehicles / Showroom / Soul / 1。网址中的车辆名称是可选的,因此网址可以是localhost:44357 / Vehicles / Showroom / 1.

我希望这是有道理的

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

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

对于问题2:[SiteMapPreserveRouteData]应该做的伎俩