Ian Anderson
Ian Anderson

Reputation: 35

mvcsitemapprovider Not all configured nodes could be paired with a parent node

I am trying to dynamically create my site map using DynamicNodeProvider Base but I am receiving the following error:

Not all configured nodes could be paired with a parent node. Check your parent keys to ensure that a node with a corresponding key exists in the SiteMap. Note that the match is case sensitive.

SiteMapCacheKey: 'sitemap://localhost/'

Orphaned Nodes:

ParentKey: 'Product' | Controller: 'Products' | Action: 'Product' | Area: '' | URL: '/Products/Product/Product1' | Key: '05633af0-b362-411b-856b-5e16b8ed1fbd' | Source: 'company.infrastructure.ProductsDynamicNodeProvider, project'

The error presents a full list of all my products so I can tell that it is trying to load the full catalog but I am missing a pairing somewhere.

Here is my Mvc.sitemap

<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="Home" controller="Home" action="Index">
    <mvcSiteMapNode title="Products" controller="Products" action="Index">
        <mvcSiteMapNode title="Details" controller="Products" action="Product" dynamicNodeProvider="MWH2.infrastructure.ProductsDynamicNodeProvider, MWH2"/>
    </mvcSiteMapNode>
    <mvcSiteMapNode title="About" controller="Home" action="About"/>
    <mvcSiteMapNode title="Careers" controller="Careers" action="Index"/>
    <mvcSiteMapNode title="Literature" controller="Literature" action="Index"/>
    <mvcSiteMapNode title="Locations" controller="Locations" action="Index"/>
    <mvcSiteMapNode title="Customer Service" controller="Customers" action="Index"/>

    </mvcSiteMapNode>

</mvcSiteMap>

ProductsDynamicNodeProvider.cs

public class ProductsDynamicNodeProvider : DynamicNodeProviderBase
    {
        public override IEnumerable<DynamicNode> GetDynamicNodeCollection(ISiteMapNode node)
        {
            ProductModel model = new ProductModel();   
            using (var prodDB = new MWH2Data())
            {
                model.Product = (from prod in prodDB.Products select prod).ToList(); 
            }

            foreach(var p in model.Product)
            {
                DynamicNode dynamicNode = new DynamicNode();
                dynamicNode.Title = p.ProductName;
                dynamicNode.ParentKey = "Product";
                dynamicNode.RouteValues.Add("id", p.ProductCleanLink);

                yield return dynamicNode;
            }
        }

    }

I have gone over the tutorials and can not find anything relating to parent nodes. Any assistance would be much appreciated.

Upvotes: 1

Views: 2038

Answers (2)

Bleak Morn
Bleak Morn

Reputation: 159

Recently upgraded site from MVC4 to MVC5 and suddenly encountered this error - everything pointing to "Home" was orphaned.

Cracked open Mvc.sitemap and changed:

<mvcSiteMapNode title="Home" controller="Home" action="Index">

...to:

<mvcSiteMapNode title="Home" controller="Home" action="Index" key="Home">

Problem solved. Most of the time was spent finding this post! Thanks for posting it so long ago. It's still helping. :P

Upvotes: 2

NightOwl888
NightOwl888

Reputation: 56849

You are specifying "Product" as your parent key, but there are no nodes defined that have "Product" as its key. You need to explicitly set the key of a node somewhere to "Product" so MvcSiteMapProvider knows which parent node they belong to.

<mvcSiteMapNode title="Products" controller="Products" action="Index" key="Product">

Upvotes: 2

Related Questions