Problem with child-nodes in dynamic mvcSiteMapNodes

Sep 8, 2010 at 5:24 PM
Edited Sep 10, 2010 at 9:20 AM

Hi!

Here is my sitemap:

<mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-2.0" enableLocalization="true">
    <mvcSiteMapNode title="Start" controller="Home" action="Index" changeFrequency="Always" updatePriority="Normal">
        <mvcSiteMapNode title="Products" controller="Products" action="Index" changeFrequency="Always" updatePriority="Normal">
            <mvcSiteMapNode title="_Dynamic_" action="Details" dynamicNodeProvider="Project.Web.ProductListDynamicNodeProvider, Project.Web">
                <mvcSiteMapNode title="Prices" action="Prices"/>
            </mvcSiteMapNode>
        </mvcSiteMapNode>
    </mvcSiteMapNode>
</mvcSiteMap>

When you type an address:

~/Products/Details/1

you will get a "breadcrumb trail" like this:

Start > Products > First Product

BUT

When you type address:

 ~/Products/Prices/1

 you will get an empty string...

The output should be:

Start > Products > First Product > Prices

So where could be a problem?

 

Thanks,

Chris

Coordinator
Sep 9, 2010 at 5:43 PM

Can you post your ProductListDynamicNodeProvider?

Sep 10, 2010 at 9:19 AM

Here you go:

    public class ProductListDynamicNodeProvider : DynamicNodeProviderBase
    {
        public override IEnumerable<DynamicNode> GetDynamicNodeCollection()
        {
            var cpa = (IContainerProviderAccessor)HttpContext.Current.ApplicationInstance;
            var cp = cpa.ContainerProvider;

            var productsRepository = cp.RequestLifetime.Resolve<IRepository<Product>>();

            foreach (var product in productsRepository)
            {
                var node = new DynamicNode {Key="ProductList:" + product.Id, Title = product.Name};
                node.RouteValues.Add("id", product.Symbol);
                
                yield return node;
            }
        }
    }
Sep 10, 2010 at 9:32 AM

Maybe I have to create another DynamicNodeProvider for my "Prices node"? And then, for each product I have to create a child-node "Price", that has a parent node named: "ProductList:" + product.Id.

Is this workaround ok?

Chris

Coordinator
Sep 10, 2010 at 11:26 AM

That will probably fix it.