如何在“类别”列表中显示子类别,例如:
根类别#1
根类别#2
Nopcommerse v2.60
答案 0 :(得分:1)
您需要使用
之类的东西扩展CategoryNavigationModelpublic IList<CategoryNavigationModel> ChildCategoryNavigationModels { get; set; }
然后在CatalogController中的CategoryNavigation操作中添加一个用于添加子类别的循环
foreach (var categoryNavigationModel in model)
categoryNavigationModel.ChildCategoryNavigationModels =
GetChildCategoryNavigationModel(new List<Category>(), categoryNavigationModel.Id, currentCategory, 0);
然后在CategoryNavigation.cshtml中,您可以在@foreach中显示子类别(模型中的var类别)
以这种方式:
<ul>
@foreach (var subCategory in category.ChildCategoryNavigationModels)
{
<li>
<a href="@Url.RouteUrl("Category", new { categoryId = subCategory.Id, SeName = subCategory.SeName })">
@subCategory.Name
</a>
</li>
}
</ul>