返回顶部

收藏

操作方法分页结果,使用PetaPoco和MvcContrib发送到视图

更多
public ActionResult Index(int? page)
        {
            //Normally, with a big ORM, using AsPagination to lazy Paginate would work fine.
            //but it's in-efficient to do this using PetaPoco
            //var pagedList = Db.Query<SomeModel>("").AsPagination(page ?? 1, 10);

            //...so we'll do it the PetaPoco way for efficient results
            var dbPage = Db.Page<SomeModel>(page ?? 1, 10, "");

            //see if the Db really ran effient sql
            Trace.Write(Db.LastCommand, "SQL to get resulsts");

            //Instead of AsPagination, CustomPagination works, providing "TotalItems" param
            var viewModel = new CustomPagination<SomeModel>(
                dbPage.Items,
                (int)dbPage.CurrentPage,
                (int)dbPage.ItemsPerPage,
                (int)dbPage.TotalItems);

            return View(viewModel);
        }

标签:c#

收藏

0人收藏

支持

0

反对

0

发表评论