Ejemplo n.º 1
0
        //              <div class="pagination pagination-centered">
        //  <ul>
        //    <li class="active"><a href="#">1</a></li>
        //    <li><a href="#">2</a></li>
        //    <li><a href="#">3</a></li>
        //    <li><a href="#">4</a></li>
        //    <li><a href="#">5</a></li>
        //  </ul>
        //</div>
        public static MvcHtmlString PageLinks(this HtmlHelper html, PagingInfo pageInfo, Func<int, string> pageUrlDelegate)
        {
            if (pageInfo.TotalPages <= 1)
                return new MvcHtmlString(string.Empty);

            var result = new StringBuilder();
            for (int page = 1; page <= pageInfo.TotalPages; page++)
            {
                var a = new TagBuilder("a") { InnerHtml = page.ToString()};
                a.MergeAttribute("href", pageUrlDelegate(page));

                var li = new TagBuilder("li") {InnerHtml = a.ToString()};

                if (page == pageInfo.CurrentPage)
                    li.AddCssClass("active");

                result.Append(li.ToString());
            }
            var ul = new TagBuilder("ul") {InnerHtml = result.ToString()};
            var div = new TagBuilder("div") {InnerHtml = ul.ToString()};

            div.AddCssClass("pagination pagination-centered");

            return new MvcHtmlString(div.ToString());
        }
Ejemplo n.º 2
0
        public void helper_should_not_generate_markup_if_TotalPages_1_or_les()
        {
            HtmlHelper helper = null;
            var pagingInfo = new PagingInfo
            {
                CurrentPage = 1,
                TotalItem = 9,
                ItemsPerPage = 10
            };

            MvcHtmlString result = helper.PageLinks(pagingInfo, n => n.ToString());

            Assert.Empty(result.ToString());
        }
Ejemplo n.º 3
0
        public ActionResult List(int page = 1)
        {
            var users = _userRepository.Users.Skip((page - 1)*PageSize).Take(PageSize);
            var pageInfo = new PagingInfo
                               {
                                   CurrentPage = page,
                                   ItemsPerPage = PageSize,
                                   TotalItem = _userRepository.Users.Count()
                               };

            var form = new UsersListForm
                           {
                               Users = users.ToList(),
                               PagingInfo = pageInfo
                           };
            return View(form);
        }
Ejemplo n.º 4
0
        public void helper_should_generage_valid_markup()
        {
            HtmlHelper helper = null;
            var pagingInfo = new PagingInfo
                                        {
                                            CurrentPage = 2,
                                            TotalItem = 28,
                                            ItemsPerPage = 10
                                        };

            Func<int, string> pageUrlDelegate = n => "Page" + n;

            MvcHtmlString result = helper.PageLinks(pagingInfo, pageUrlDelegate);

            Assert.Equal(result.ToString(),
                    "<div class=\"pagination pagination-centered\">" +
                        "<ul>" +
                        "<li><a href=\"Page1\">1</a></li>" +
                        "<li class=\"active\"><a href=\"Page2\">2</a></li>" +
                        "<li><a href=\"Page3\">3</a></li>" +
                        "</ul>" +
                    "</div>"
                    );
        }
Ejemplo n.º 5
0
        public ActionResult List(string category = "", int page = 1)
        {
            long totalItem;
            var query = !string.IsNullOrEmpty(category) ? Query.EQ("Category", category.ToUpper()) : null;
            var companies = Collection<CompanyViewModel>().GetPage(query, page, PageSize, out totalItem);
            var pageInfo = new PagingInfo
                               {
                                   CurrentPage = page,
                                   ItemsPerPage = PageSize,
                                   TotalItem = (int)totalItem
                               };

            return View(new CompaniesListViewModel
            {
                Companies = companies,
                PagingInfo = pageInfo,
                Category = category
            });
        }