James Andrew Smith
James Andrew Smith

Reputation: 1566

MvcSiteMapProvider only showing when editing mvc.sitemap mvc4

Can anyone help me with mvcsitemapprovider. The breadcrumbs on the sitemap refuse to display untill i edit the mvc.siemap file and save. It will then only temporary show the breadcrumb untill i leave the page and reopen it.

my setup..

<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-4.0"
        xsi:schemaLocation="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-4.0     
MvcSiteMapSchema.xsd">

<mvcSiteMapNode title="Dashboard" controller="Dashboard" action="Index">
<mvcSiteMapNode title="Customers" controller="Customers" action="Index">
  <mvcSiteMapNode title="Details" controller="Customers" action="Details"  />
  <mvcSiteMapNode title="Edit" controller="Customers" action="Edit" />   
</mvcSiteMapNode>
</mvcSiteMapNode>

Upvotes: 0

Views: 708

Answers (1)

NightOwl888
NightOwl888

Reputation: 56849

From the looks of things, you are trying to show the breadcrumb on administration pages. The recommended way of doing that is to use preservedRouteParameters to force every "id" to match the node, and then use visibility providers and [TitleAttribute] to fix the display when changing between records and to hide these options from the main menu (usually you will want to navigate to the index page first and then select the commands from a database driven list, so they shouldn't appear in the menu).

<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-4.0"
        xsi:schemaLocation="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-4.0     
MvcSiteMapSchema.xsd">

<mvcSiteMapNode title="Dashboard" controller="Dashboard" action="Index">
<mvcSiteMapNode title="Customers" controller="Customers" action="Index">
  <mvcSiteMapNode title="Create New" controller="Customers" action="Create"  visibility="SiteMapPathHelper,!*" />
  <mvcSiteMapNode title="Details" controller="Customers" action="Details"  visibility="SiteMapPathHelper,!*" preservedRouteParameters="id">
    <mvcSiteMapNode title="Edit" controller="Customers" action="Edit" visibility="SiteMapPathHelper,!*" preservedRouteParameters="id" />
    <mvcSiteMapNode title="Delete" controller="Customers" action="Delete" visibility="SiteMapPathHelper,!*" preservedRouteParameters="id" />
  </mvcSiteMapNode>  
</mvcSiteMapNode>
</mvcSiteMapNode>

The fact that they show up at all shouldn't be happening without using preservedRouteParameters. That could either be a bug or a misconfiguration, but without more details about your configuration it is hard to tell.

You can see a complete downloadable demo of this at How to Make MvcSiteMapProvider Remember a User's Position (see the Forcing a Match project). Be sure to also see the documentation about the visibility and title attribute on the wiki.

Upvotes: 1

Related Questions