2
votes

Hi I'm using c# mvc MvcSiteMapProvider.

I've got a section of my site set up like this in the mvc.sitemap file.

<mvcSiteMapNode title="Reports" controller="Reports" action="Index">
      <mvcSiteMapNode title="Directorates" controller="ReportsDirectorate" action="Index" key="ReportsDirectorate">
        <mvcSiteMapNode title="Divisions" controller="ReportsDirectorate" action="Directorate" key="ReportsDirectorateDirectorate" preservedRouteParameters="id">
           <mvcSiteMapNode title="Teams" controller="ReportsDirectorate" action="Division" preservedRouteParameters="id,divisionId">
              <mvcSiteMapNode title="Team" controller="ReportsDirectorate" action="Team" preservedRouteParameters="id,divisionId,teamId"/>
           </mvcSiteMapNode>
        </mvcSiteMapNode>
      </mvcSiteMapNode>

    </mvcSiteMapNode>

The final node title="team" has an offending action in the controller like this.

 [MvcSiteMapNode(Key  = "ReportsDirectorateDirectorate", ParentKey = "ReportsDirectorate", Title = "Soimething here")]
 [SiteMapTitle("team.Division.Name", Target = AttributeTarget.ParentNode)]
 [SiteMapTitle("team.Name")]
 public ActionResult Team(int teamId)

I'm trying to influence the title for this node which is basically the ParentNode's Parent, for use in the breadcrumb.

<mvcSiteMapNode title="Divisions" controller="ReportsDirectorate" action="Directorate" key="ReportsDirectorateDirectorate" preservedRouteParameters="id">

How do you do this? Thanks Richard

1
can you post the solution with your code, how exactly you made it work. - anu
Use the code below within the action in question - Richard Housham
Thanks. I had 2 different sitemaps for different areas. It was picking the wrong sitemap and returning null for the current node, hence I asked for the code. - anu

1 Answers

2
votes

Within the controller you can access any node with greater presion.

 MvcSiteMapProvider.SiteMaps.Current.CurrentNode.ParentNode.ParentNode.Title = team.Division.Directorate.Name;

This is also useful if say you want to use the same action, but perhaps a different title depending on route values or some other parameter.