Exemplo n.º 1
0
        public IActionResult Index(int p = 1)
        {
            var currentPageNum = p;
            var offset         = (DefaultPageSize * currentPageNum) - DefaultPageSize;
            var model          = new ProductListViewModel();

            model.Products.Data = this.allProducts
                                  .Skip(offset)
                                  .Take(DefaultPageSize)
                                  .ToList();

            model.Products.PageNumber = currentPageNum;
            model.Products.PageSize   = DefaultPageSize;
            model.Products.TotalItems = allProducts.Count;


            return(View(model));
        }
Exemplo n.º 2
0
        public IActionResult IndexAjax()
        {
            var model = new ProductListViewModel();

            model.Products.Data = this.allProducts
                                  .Take(DefaultPageSize)
                                  .ToList();


            model.Products.PageNumber = 1;
            model.Products.PageSize   = DefaultPageSize;
            model.Products.TotalItems = allProducts.Count;

            return(PartialView("_PagingModal", model));

            //if (HttpContext.Request.IsAjaxRequest())
            //{

            //    return PartialView("_PagingModal", model);
            //}
            return(View(model));
        }
Exemplo n.º 3
0
        //[Route("paging/ajaxpage/{page?}")]
        public async Task <IActionResult> AjaxPage(int?page)
        {
            ViewBag.Title = "Browse all products";

            var currentPageNum = page.HasValue ? page.Value : 1;
            var offset         = (DefaultPageSize * currentPageNum) - DefaultPageSize;

            var model = new ProductListViewModel();

            model.Products.Data = this.allProducts
                                  .Skip(offset)
                                  .Take(DefaultPageSize)
                                  .ToList();

            model.Products.PageNumber = currentPageNum;
            model.Products.PageSize   = DefaultPageSize;
            model.Products.TotalItems = allProducts.Count;

            // simulate delay to show the loadinng indicator
            await Task.Delay(2000);//milliseconds

            return(PartialView("_ProductGrid", model));
        }