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.
You don't need a dynamic node provider.
<mvcSiteMapNode title="Person Details" controller="Information" action="PersonDetails" preservedRouteParameters="id">
<mvcSiteMapNode title="Contact Person" controller="Information" action="Contact" />
</mvcSiteMapNode>
works fine for what you're doing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With