【问题标题】:Paging with PagedList使用 PagedList 进行分页
【发布时间】:2013-04-09 09:35:02
【问题描述】:

这是我的存储库层:

public List<Section> GetAllSections()
{
    return context.Sections.Include("Groups").Include("Groups.Classes").ToList();
}

这是我的应用层:

public List<Section> GetAllSections()
{
    return cacheSectionRepo.GetAllSections();
}

在控制器中我有:

SectionApplication sectionApp = new SectionApplication();
public ActionResult Index()
{
    return View(sectionApp.GetAllSections());
}

现在我想让我的Index 视图分页。我想从 PagedList 中使用。我应该怎么做? 例如我希望每页显示 5 条记录。

【问题讨论】:

    标签: asp.net-mvc-3 pagination pagedlist


    【解决方案1】:

    您可以将页码和页面大小传递给存储库层,然后使用SkipTake Linq 语句过滤掉您需要的行:

    public List<Section> GetAllSections(int pageSize=5, int pageNo)
    {
        return cacheSectionRepo.GetAllSections().Skip(pageSize * pageNo).Take(pageSize);;
    }
    

    或者,您可以在您的存储库层中执行该过滤。然后,对于控制器的每个请求,您都会将pageNo 发送到控制器,最好是通过 AJAX 请求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-04
      • 2020-10-01
      • 2013-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多