参数是int pageSize , int currentPage
//修正第一页
if (PageIndex<1)
{
PageIndex = 1;
}
//查询
var list = dal.Show();
if (!string.IsNullOrEmpty(account))
{
list = list.Where(s => s.Account.Contains(account)).ToList();
}
//查询出总数据
var TotalCount = list.Count();
int totalPage;//总页数
if (TotalCount%PageSize==0)
{
totalPage = TotalCount / PageSize;
}
else
{
totalPage = TotalCount / PageSize + 1;
}
//纠正当前页数>总页数
if (PageIndex>totalPage)
{
PageIndex = totalPage;
}
//Linq分页查询列表
list = list.Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList();
var m = new PageModel();
m.list = list;
m.TotalPage = totalPage;
m.PageIndex = PageIndex;
m.TotalCount = TotalCount;
return m;
}
API Linq分页
最新推荐文章于 2021-03-17 04:26:39 发布