【发布时间】:2017-05-10 11:34:48
【问题描述】:
我需要在 Web 应用程序中使用 MVCSitemap 提供程序,但我无法在我有动态 url 的地方使用它。
我有一个类别列表,其中可以有父母和孩子。 例如,如果我点击一个类别,面包屑如下所示:
Home > Filter
如果我点击过滤器的一个孩子,我会得到:
Filter > Air filter
主页链接消失。 如果我点击我得到的“空气过滤器”的孩子:
Air filter > air filter children
等等。始终显示最后两个级别,如果我单击第一级,则始终返回主页。
这是在我的 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>
这是来自 Product 控制器的 Subcategories 方法:
[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;
}
你能帮我吗,我在这里做错了什么? 我查看了网上所有的解释,尝试了很多方法,但都没有解决这个问题。
【问题讨论】:
标签: asp.net-mvc mvcsitemapprovider