public static MvcHtmlString AjaxPageLinks(this AjaxHelper html, PagingInfo pageingInfo) { StringBuilder str = new StringBuilder(); bool bThreeDots1 = false; bool bThreeDots2 = false; int links_visible = 2; var currentPage = pageingInfo.CurrentPage; var totalPages = pageingInfo.TotalPage; int links_visible_head = links_visible; if (links_visible >= (currentPage - links_visible)) links_visible_head = 3; int links_visible_tail = links_visible; if ((currentPage + links_visible) >= (totalPages - links_visible)) links_visible_tail = links_visible * 2 + 1; for (int i = 1; i <= totalPages; i++) { if (i <= links_visible_head || i > (totalPages - links_visible_tail) || (i <= currentPage && i >= (currentPage - links_visible)) || (i >= currentPage && i <= (currentPage + links_visible))) { TagBuilder tag = new TagBuilder("a"); tag.MergeAttribute("href", "javascript:void()"); tag.InnerHtml = i.ToString(); tag.MergeAttribute("data-service", pageingInfo.Service); tag.MergeAttribute("data-page", i.ToString()); if (pageingInfo.CatId != null) { tag.MergeAttribute("data-catid", pageingInfo.CatId.ToString()); } tag.AddCssClass("page-link k-button"); if (i == currentPage) tag.AddCssClass("current-page k-button k-primary"); str.Append(tag.ToString()); } else { if (i < currentPage) { if (!bThreeDots1) { str.Append("..."); bThreeDots1 = true; } } else { if (!bThreeDots2) { str.Append("..."); bThreeDots2 = true; } } } } if (pageingInfo.TotalPage > 1) { return MvcHtmlString.Create(str.ToString()); } else return MvcHtmlString.Empty; }
public static MvcHtmlString PageLinks(this HtmlHelper html, PagingInfo pageingInfo, Func<int, string> pageUrl) { StringBuilder str = new StringBuilder(); bool bThreeDots1 = false; bool bThreeDots2 = false; int links_visible = 2; var currentPage = pageingInfo.CurrentPage; var totalPages =pageingInfo.TotalPage; int links_visible_head = links_visible; if (links_visible >= (currentPage - links_visible)) links_visible_head = 3; int links_visible_tail = links_visible; if ((currentPage + links_visible) >= (totalPages - links_visible)) links_visible_tail = links_visible * 2 + 1; for (int i = 1; i <= totalPages; i++) { if (i <= links_visible_head || i > (totalPages - links_visible_tail) || (i <= currentPage && i >= (currentPage - links_visible)) || (i >= currentPage && i <= (currentPage + links_visible))) { TagBuilder tag = new TagBuilder("a"); tag.MergeAttribute("href", pageUrl(i)); tag.InnerHtml = i.ToString(); if (i == currentPage) tag.AddCssClass("current-page k-primary k-button"); else tag.AddCssClass("k-button"); str.Append(tag.ToString()); } else { if (i < currentPage) { if (!bThreeDots1) { str.Append("..."); bThreeDots1 = true; } } else { if (!bThreeDots2) { str.Append("..."); bThreeDots2 = true; } } } } if (pageingInfo.TotalPage > 1) { return MvcHtmlString.Create(str.ToString()); } else return MvcHtmlString.Empty; }
public ActionResult ProdListPartial(string jsonData) { JObject obj2 = JObject.Parse(jsonData); int id = obj2.SelectToken("catId").Value<int>(); int num = obj2.SelectToken("page").Value<int>(); ProductListViewModel model2 = new ProductListViewModel { Products = (from x in _pRepository.Products where x.CategoryID == id orderby x.ID descending select x).Skip<Product>(((num - 1) * this.PageSize)).Take<Product>(this.PageSize) }; PagingInfo info = new PagingInfo { Service = "Product", CurrentPage = num, ItemsPerPage = this.PageSize, TotalItems = (from x in this._pRepository.Products where x.CategoryID == id select x).Count<Product>(), CatId = id }; model2.PagingInfo = info; ProductListViewModel model = model2; return PartialView(model); }