public ActionResult Index(string id) { long?Id = Convert.ToInt64(CommonFile.Decode(id)); Services.SetCookie(this.ControllerContext.HttpContext, "ProductCatId", id.ToString()); ListAllProduct = CommonFile.GetProduct(); ProductModel objmodel = new ProductModel(); var SearchProductList = new List <ProductModel>(); if (!CommonFile.IsParentCategory(Id)) { SearchProductList = ListAllProduct.Where(x => x.ProductCatId == Id).ToList(); } else { SearchProductList = ListAllProduct.Where(x => x.ParentCatId == Id).ToList(); } ViewBag.SearchCatId = id; ViewBag.UsersProduct = SearchProductList; ViewBag.SearchResultCount = SearchProductList.Count; var ProductCatList = CommonFile.GetProductCategory(null); var EncodedCategories = new List <DropDownModel>(); foreach (var item in ProductCatList) { DropDownModel dropDown = new DropDownModel(); dropDown.Name = item.Name; dropDown.Id = item.Id; dropDown.EncodedId = CommonFile.Encode(item.Id.ToString()); dropDown.CatIdEncoded = CommonFile.Encode(item.ParentCatId.ToString()); dropDown.ParentCatId = item.ParentCatId; EncodedCategories.Add(dropDown); } int pageindex = 1; ViewBag.UsersProduct = SearchProductList.Skip((pageindex - 1) * Constant.NumberOfProducts).Take(Constant.NumberOfProducts); ViewBag.LowerLimit = ((pageindex / 5) * 5) + 1; ViewBag.PageIndex = pageindex; ViewBag.ProductsFrom = ((pageindex - 1) * Constant.NumberOfProducts); ViewBag.ToProductsCount = Enumerable.Count(ViewBag.UsersProduct); ViewBag.SearchResultCount = SearchProductList.Count; ViewBag.LowerLimit = 1; int nop = SearchProductList.Count / Constant.NumberOfProducts; int remindernop = SearchProductList.Count % 12; if (nop < Constant.NumberOfPages) { if (remindernop > 0) { nop = nop + 1; } ViewBag.NumberOfPages = nop; } else { ViewBag.NumberOfPages = Constant.NumberOfPages; } var ProductCategory = ProductCatList.Where(x => x.Id.Equals(Id)); ViewBag.ProductCatList = EncodedCategories.Where(x => x.ParentCatId == ProductCategory.Single().ParentCatId); if (!CommonFile.IsParentCategory(Id)) { objmodel.ParentCatId = ProductCategory.Single().ParentCatId; } else { objmodel.ParentCatId = ProductCategory.Single().Id; } objmodel.CategoryName = ProductCategory.Single().Name; return(View(objmodel)); }