I need to use MVCSitemap provider in a web application, but I can't make it work where I have dynamic urls.
I have a list of categories, which can have parents and children. For example if I click on a category, the breadcrumb looks like this:
Home > Filter
if I click on a children of the Filter, I got:
Filter > Air filter
the Home link disappears. If I click on the childrens of the "Air filter" I got:
Air filter > air filter children
and so on. Always the two last levels are showed, and if I click on the first level, always goes back to the Home page.
This is in my MvcSitemap:
<mvcSiteMapNode title="Home" controller="Home" action="Index">
<mvcSiteMapNode title="Product" controller="Product" action="SubCategories" preservedRouteParameters="selected,category,id,engineId">
<mvcSiteMapNode title="Details" controller="Product" action="ProductDetails" preservedRouteParameters="supplierName,code,name,prodId,-1"/>
</mvcSiteMapNode>
</mvcSiteMapNode>
This is the Subcategories method from Product controller:
[MvcSiteMapNode(Title = "Article", ParentKey = "SubCategories")]
[Route("{selected}-{category}-{id}-{engineId}")]
public ActionResult SubCategories(string selected, string category, int id, string engineId)
{
...........................
SiteMaps.Current.CurrentNode.Title = categoryName;
if(categoryRepository.GetCategoryByID(id).ParentId.HasValue)
{
int parentId = categoryRepository.GetCategoryByID(id).ParentId.Value;
string parentName = categoryRepository.GetCategoryByID(parentId).Name;
SiteMaps.Current.CurrentNode.ParentNode.RouteValues["id"] = id;
SiteMaps.Current.CurrentNode.ParentNode.Title = parentName;
}
Can you please help me, what I'm doing wrong here? I checked all the explanations on the web, I tried in many ways, but none of them resolved this problem.