【发布时间】:2016-11-05 07:47:54
【问题描述】:
我有带有 WCF 服务的 MVC 项目。
当我显示数据列表时,我确实想从数据库/服务加载所有内容并进行客户端分页。但我确实想要一个服务器端分页。如果我有 100 条记录并且我的页面大小为 10,那么当用户单击第 1 页时,它只会从数据库中检索前 10 条记录,如果用户单击第 3 页,则它将仅检索相应的 10 条记录. 我没有使用 Angular 或任何其他引导程序。
谁能指导我怎么做?
public ActionResult Index(int pageNo = 1)
{
..
..
..
MyViewModel[] myViewModelListArray = MyService.GetData();
//when I create this PageList, BLL.GetData have to retreive all the records to show more than a single page no.
//But if the BLL.GetData() was changed to retrieve a subset, then it only shows a single page no.
//what I wanted to do is, show the correct no of pages (if there are 50 records, and pageSize is 10, then show
//page 1,2,3,4,5 and only retrieve 10 records at a time.
PagedList<MyViewModel> pageList = new PagedList<<MyViewModel>(myViewModelListArray, pageNo, pageSizeListing);
..
..
..
return View(pageList);
}
【问题讨论】:
-
您能否发布一些代码,向我们展示您已经尝试过但不起作用的内容?向大家展示你在什么样的环境中工作以及你正在使用的编码风格将有很长的路要走。
-
请显示一些代码。您也可以尝试将 start 和 limit 传递给服务器,以便告诉服务器应该返回哪些特定的记录集。
-
@bogzy 如果我通过传入 PageSize 和 PageNo 来限制要返回的特定记录集,那么它只显示一个页面。
标签: c# asp.net-core-mvc paging server-side