开发者

MVC Sitemap Provider Persist Parameters

This has been driving me crazy for the last couple of hours. I am using the MVC Sitemap Provider to add breadcrumb functionality.

Let me go through the steps of what I have done so I can make this as clear as possible

  • Downloaded the resource from Nuget
  • I then have the following in my sitemap

    <?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>
    

  • And I have this in my view

    开发者_Go百科

    @Html.MvcSiteMap().SiteMapPath()

  • My first questions is: How can I have in replace "VehicleName" for action Showroom, with my actual VehicleName?

  • My actual problem is: My id is not persisted through to the parent. For example my url will be localhost:44357/Vehicles/Overview/Soul/1, and the parent url will be localhost:44357/Vehicles/Showroom, instead of localhost:44357/Vehicles/Showroom/Soul/1. The vehiclename in the url is optional, so the url can just be localhost:44357/Vehicles/Showroom/1.

I hope this makes sense

Thanks for your help.


For questions 1: Set the VehicleName on the parent node. For example: ((MvcSiteMapNode)SiteMap.CurrentNode.Parent).RouteValues.Add("VehicleName", "SomeVehicle");. A good option may also be to use dynamic node providers for creating your sitemap structure.

For question 2: [SiteMapPreserveRouteData] should do the trick

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜