实施分页

时间:2014-12-24 20:35:21

标签: asp.net-mvc-4 pagedlist

我有以下行动

public ActionResult ViewModelProducts()
        {
            var listOfProductsBuy = db.ProductsBuy.Select(x => new ProductBuyViewModel
            {
                Id = x.Id,
                Title = x.Title,
                ProductBuyId = x.Id,
                Author = x.Author,
                MasterImageUrl = x.Images.FirstOrDefault().Url,
                Price = x.Price,
                Values = x.Value,

            }).ToList();
            var listOfProductsRent = db.ProductsRent.Select(y => new ProductRentViewModel
            {
                Id = y.Id,
                Title = y.Title,
                MasterImageUrl = y.ImagesRent.FirstOrDefault().Url,
                ProductRentId = y.Id,
                Author = y.Author,
                Period = y.Period.PeriodOfTime,
                Price = y.Price,
                Values = y.Value,
            }).ToList();

            var listOfProductsSearch = db.ProductSearches.Select(z => new ProductSearchViewModel
            {
                Id = z.Id,
                Title = z.Title,
                ProductSearchId = z.Id,
                Author = z.Author,
                MasterImageUrl = z.ImagesSearch.FirstOrDefault().Url,
                Price = z.Price,
                Values = z.Value,
            }).ToList();

            var viewModel = new AllProductsViewModel { ProductBuy = listOfProductsBuy, ProductRent = listOfProductsRent, ProductSearch = listOfProductsSearch};
            return View(viewModel);
        }

我想为多个viewmodel实现分页。如果有方法使用PagedList会更好,但如果没有,它也会没问题。

1 个答案:

答案 0 :(得分:0)

为了添加分页,您可以安装PagedList.MVC Nuget包。您可以在Microsoft网站here上看到确切的分步过程。查看名为“添加寻呼到学生索引页面”的部分。希望这会有所帮助。