Beispiel #1
0
        public static MvcHtmlString PageLinks(this HtmlHelper html,
                                              PagingInfo pagingInfo,
                                              Func<int, string> pageUrl)
        {
            StringBuilder result = new StringBuilder();
            for (int i = 1; i <= pagingInfo.TotalPages; i++)
            {
                TagBuilder tag = new TagBuilder("a");
                tag.MergeAttribute("href", pageUrl(i));
                tag.InnerHtml = i.ToString();
                tag.AddCssClass("pageNumber");
                if (i == pagingInfo.CurrentPage)
                    tag.AddCssClass("selected");
                result.Append(tag.ToString());
            }

            return MvcHtmlString.Create(result.ToString());
        }
        public PartialViewResult ProductList(int page = 1, string searchString = "")
        {
            Func<Product, bool> nameFilter = p => p.Name.Contains(searchString);

            var products = _productRepo.GetProducts(PageSize * (page - 1), PageSize, nameFilter);

            var pageInfo = new PagingInfo { CurrentPage = page,
                                            ItemsPerPage = PageSize,
                                            TotalItems = _productRepo.GetProducts(0, null, nameFilter).Count()
            };

            var vm = new ProductListViewModel { Products = products,
                                                PagingInfo = pageInfo,
                                                SearchString = searchString
                                                };

            return PartialView("_PageableProductList", vm);
        }