hi ,

i would like to display my site map categorized as categories and sub categories. those sub categories further have child sub categories. i'm getting only the last child subcategory. somewhere i've did a mistake. thanks in advance

here is  my controller code.

public ActionResult SitemapSubCat()
        {
            var model = new SitemapSubCatModel();
            if (_commonSettings.SitemapIncludeCategories)
            {
                var categories = _categoryService.GetAllCategoriesDisplayedOnHomePage();
                model.Categories = categories.Select(x => x.ToModel()).ToList();

                foreach (var cat in model.Categories)
                {
                    cat.SubCategories = _categoryService.GetAllCategoriesByParentCategoryId(cat.Id)
                       .Select(x =>
                       {
                           var subCatName = x.GetLocalized(y => y.Name);
                           var subCatModel = new CategoryModel.SubCategoryModel()// CategoryModel.SubCategoryModel()
                           {
                               Id = x.Id,
                               Name = subCatName,
                               SeName = x.GetSeName(),
                           };
                           return subCatModel;
                       }).ToList();
                    //model.childCategory = cat.SubCategories.ToList();

                    foreach (var subcat in cat.SubCategories)
                    {
                        model.subChildCat = _categoryService.GetAllCategoriesByParentCategoryId(subcat.Id)
                           .Select(x =>
                           {
                               var childCatName = x.GetLocalized(y => y.Name);
                               var childCatModel = new CategoryModel.SubCategoryModel()// CategoryModel.SubCategoryModel()
                               {
                                   Id = x.Id,
                                   Name = childCatName,
                                   SeName = x.GetSeName(),
                               };
                               return childCatModel;
                           }).ToList();

                    }
                }

            }
            return View(model);
        }


and my view page code is

@if (Model.Categories.Count > 0)
        {
            <div class="entity">
                <div class="title">Sub Category</div>
                
                <div class="category-box">
                    @foreach(var items in Model.Categories)
                    {
                        <div class="category-division" style="height:auto; margin-bottom:15px;">
                            @if(items.SubCategories.Count > 0)
                            {
                                foreach (var subcat in items.SubCategories)
                                {
                                    if (items.SubCategories.Count > 0)
                                    {
                                        foreach (var childcat in Model.subChildCat)
                                        {
                                            <div class="child-category-box" style="margin:15px;">
                                                <ul>
                                                    <li style="float:left; width:250px; list-style-type:none; margin:5px 0px; text-align:left; font-size:12px;">
                                                        <a href="@Url.RouteUrl("Category", new { categoryId = childcat.Id, SeName = childcat.SeName })">@childcat.Name</a>
                                                    </li>
                                                </ul>
                                            </div>
                                        }

                                    }
                                }
                            }
                        </div>
                    }

                </div>
            </div>
          
            <div class="clear">
            </div>
        }