Children of dynamic nodes don't show up in breadcrumbs or sitemap

Jun 21, 2011 at 8:24 PM

I am trying to develop of sitemap for my site that maintains URL parameters when it needs to. I'm using MvcSiteMapProvider and trying to use dynamic nodes to preserve the route data for various nodes. However, the problem I'm having is with the children of dynamic nodes. When I nest a node within a dynamic node in my sitemap file, it doesn't show up on the sitemap generated using Html.MvcSiteMap().SiteMap(), and when I navigate to the page, I lose all of the breadcrumbs BEFORE the dynamic node.

For example, if my dynamic node is called "Person Details", the breadcrumb looks like this on the Person Details page:

Home > People > Person Details

But as soon as I navigate further into the page, say "Contact Person", the breadcrumb looks like this:

Person Details > Contact Person

without the first two paths. Also if I try to navigate back to Person Details, none of the url parameters are maintained (e.g. instead of going to http://localhost:55555/Home/People/PersonDetails?id=12, it goes to http://localhost:55555/Home/People/PersonDetails).

When I try to display the whole sitemap by using Html.MvcSiteMap().SiteMap(), it outputs the correct hierarchy up until the dynamic node. The sitemap lists a unique node for each "Person" node found in the dynamic node provider, but does not display any of the children of the dynamic node.

My sitemap looks something like this (abbreviated):

<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0" enableLocalization="true">
  <mvcSiteMapNode title="Home"  controller="Home" action="Index">
    <mvcSiteMapNode title="People" controller="Information" action="People">
      <mvcSiteMapNode title="Person Details" controller="Information" action="PersonDetails" dynamicNodeProvider="MySite.Code.PersonDetailsDynamicNodeProvider, MySite">
        <mvcSiteMapNode title="Contact Person" controller="Information" action="Contact" />
      </mvcSiteMapNode>
    </mvcSiteMapNode>
  </mvcSiteMapNode>
</mvcSiteMap>

And my dynamic node provider looks like this:

public class PersonDetailsDynamicNodeProvider : DynamicNodeProviderBase
{
    List<Person> people = proxy.GetPeople();

    public override IEnumerable<DynamicNode> GetDynamicNodeCollection()
    {
        var nodes = new List<DynamicNode>();

        foreach (var person in people)
        {
            DynamicNode node = new DynamicNode();
            node.RouteValues.Add("id", person.ID);

            nodes.Add(node);
        }

        return nodes;
    }

    static private PersonServiceClient proxy = new PersonServiceClient();
}

Is there anything I am missing? I get the feeling I've just left something out, but I'm very new to web development and really am just stabbing in the dark at this point.

Coordinator
Jul 4, 2011 at 12:17 PM

Are contact persons also added as dynamic nodes?

Jul 5, 2011 at 3:31 PM

I have tried making it a dynamic node, but when I do that the breadcrumb trail disappears entirely. Instead of the shortened version when I navigate to "contact person" there is no breadcrumb trail at all. The trail displays for all other pages, until I navigate to the dynamic node's child node.

Coordinator
Jul 6, 2011 at 11:52 AM

Found the problem, it's a minor bug preventing you from doing these things. I've implemented a fix for this in the 3.1.0 branch.

When trying the new branch, modify the sitemap to:

<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0" enableLocalization="true">
  <mvcSiteMapNode title="Home"  controller="Home" action="Index">
    <mvcSiteMapNode title="People" controller="Information" action="People">
      <mvcSiteMapNode title="Person Details" controller="Information" action="PersonDetails" dynamicNodeProvider="MySite.Code.PersonDetailsDynamicNodeProvider, MySite">
        <mvcSiteMapNode title="Contact Person" controller="Information" action="Contact" inheritedRouteParameters="id" />
      </mvcSiteMapNode>
    </mvcSiteMapNode>
  </mvcSiteMapNode>
</mvcSiteMap>

Jul 6, 2011 at 3:46 PM

Thanks for the reply, I updated to the most recent version and it seems to be working fine.

Thanks a lot!

Sep 29, 2011 at 7:59 PM

I was wondering where I could get an updated copy? I have the version of 3.1.0 from NuGet, but I see there are some changes (namely the one listed above). I'm trying to do something similar and it will not work.  Here is my code in case I'm doing something wrong.

<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0" enableLocalization="true">
    <mvcSiteMapNode title="Home" controller="Home" action="Index" changeFrequency="Always" updatePriority="High">
        <mvcSiteMapNode title="States" controller="GlobalInsights" action="By" id="State">
            <mvcSiteMapNode title="AAAA" controller="States" action="Index" dynamicNodeProvider="globalEDGE_MVC.StateDetailsDynamicNodeProvider, globalEDGE-MVC">
                <mvcSiteMapNode title="Profile" action="Profile" controller="States" inheritedRouteParameters="state"/>
            </mvcSiteMapNode>

        </mvcSiteMapNode>
        <mvcSiteMapNode title="Checkout" controller="Checkout" />
    </mvcSiteMapNode>
</mvcSiteMap>

I can get the The proper State name from the dynamicNodeProvider, but cannot from the Profile action. If I take off inheritedRouteParameters I can at least see some of the breadcrumb. The breadcrumb looks like AAAA > Profile. If I add the inheritedRouteParameters, it shows nothing.

I tried building it on my own, but no luck. Do you need MVC2 for it to build? The errors have something to do with MVC.

Jan 10, 2012 at 10:06 AM

I tried adding the attribute inheritedRouteParameters="id" , but once this is added the complete sitemappath disappears.

If i dont add this attribue that it shows some bits as follows : Product Listing > Verified and when when i click on the ProductListing it gives an error saying id is null.

 Here is my sitemap:

<mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0"
            enableLocalization="true">
  <mvcSiteMapNode title="Home" controller="Home" action="Home" >
      <mvcSiteMapNode title="Product Listing" controller="Product" action="GetProductUniformat"
		  dynamicNodeProvider="Ecospex.Models.ProductNodeProvider, Ecospex" 
                      key="ProductsListCategory">

        <mvcSiteMapNode title="Verified Enhanced Listing"
                   controller="Product" action="ShowEnhancedListing" inheritedRouteParameters="id"
                   key="EnhancedListing" />
		  
		  
        <mvcSiteMapNode title="Basic Listing"
                   controller="Product" action="ShowBasicOverView"
                   isDynamic="true" dynamicParameters="ProductId"
                   key="BasicListing" />
        </mvcSiteMapNode>
 </mvcSiteMapNode>
In the above sitemap, the nodes with key BasicListing and Enhanced Listing have this problem. I am using MVC2. How do i solve this?