Alex Skorkin
Alex Skorkin

Reputation: 4274

How to show sub-categories in the Categories list

How can I show sub-categories right in the Categories list, e.g.:

Root Category #1

Root Category #2

Nopcommerse v2.60

Upvotes: 0

Views: 1817

Answers (1)

Vladimirs
Vladimirs

Reputation: 8599

You need to extend CategoryNavigationModel with something like

public IList<CategoryNavigationModel> ChildCategoryNavigationModels { get; set; }

Then in CategoryNavigation action in CatalogController add one more loop for adding sub categories

foreach (var categoryNavigationModel in model)
                    categoryNavigationModel.ChildCategoryNavigationModels =
                        GetChildCategoryNavigationModel(new List<Category>(), categoryNavigationModel.Id, currentCategory, 0);

And then in CategoryNavigation.cshtml you can display sub categories within @foreach (var category in Model)

In that way:

<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>

Upvotes: 1

Related Questions