I need to use the MVCSitemap provider in a web application, but I cannot get it to work where I have dynamic URLs.
I have a list of categories in which parents and children can be. For example, if I click on a category, the wand looks like this:
Home > Filter
If I click on the children of the filter, I get:
Filter > Air filter
The Home link will disappear. If I click on the children of the "Air Filter", I got:
Air filter > air filter children
etc. The last two levels are always displayed, and if I click on the first level, I always return to the main 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 subcategory method from the 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;
}
, ?
, , .