Hi

Hoping someone maybe able to help me with this Non Action and Public Action methods. As we know how the Categories and SubCategories map to the products in the Db.

With category sibblings im trying to pass a getchildsibblingonly method. Which does work until I pass the final category int into the product.Id. Within the partial view on the front end I can navigate to the product list but the partail view vanishes I need it to remain on the subcategory's.

Logically I have highlighted the code that I think is causing the issue but I have tryed various different operator's the block still vanishes.


Non Action Method

 
[NonAction]
        private IList<CategoryNavigationModel> GetOnlySiblings(Category currentCategory)
        {
            var result = new List<CategoryNavigationModel>();
            int Id = 0;
            if (currentCategory != null)
                Id = currentCategory.Id;

                
            foreach (var category in _categoryService.GetAllCategoriesByParentCategoryId(Id))
            {
                var model = new CategoryNavigationModel()
                {
                    Id = category.Id,
                    Name = category.GetLocalized(x => x.Name),
                    SeName = category.GetSeName(),
                    IsActive = currentCategory != null && currentCategory.Id == category.ParentCategoryId,
                    NumberOfParentCategories = 0
                };
                result.Add(model);
            }
            return result;
        }


Here is the Public Action method


[ChildActionOnly]
        //[OutputCache(Duration = 120, VaryByCustom = "WorkingLanguage")]
        public ActionResult CategoryNavigation(int currentCategoryId, int currentProductId)
        {
            string cacheKey = string.Format(ModelCacheEventConsumer.CATEGORY_NAVIGATION_MODEL_KEY, currentCategoryId, currentProductId, _workContext.WorkingLanguage.Id);
            var cacheModel = _cacheManager.Get(cacheKey, () =>
            {
                var currentCategory = _categoryService.GetCategoryById(currentCategoryId);
                if (currentCategory == null && currentProductId > 0)
                {
                    var productCategories = _categoryService.GetProductCategoriesByProductId(currentProductId);
                    if (productCategories.Count > 0)
                        currentCategory = productCategories[0].Category;
                }
                var breadCrumb = currentCategory != null ? GetCategoryBreadCrumb(currentCategory) : new List<Category>();
                var model = GetOnlySiblings(currentCategory);
                return model;
            });

            return PartialView(cacheModel);
        }


A good example would be If I changed the following

var result = new List<CategoryNavigationModel>();
            int Id = 0;
            if (currentCategory != null)
               Id = currentCategory.Id;


to

var result = new List<CategoryNavigationModel>();
            int Id = 0;
            if (currentCategory != null)
               Id = 1;


All parentcategories return to the first category which is Baby Range. So If go to another category DIY it returns all subcategories within Baby Range..

If you could help greatly appriecated...

Richard Evans