【前言】
最近小编在项目中需要通过Linq表达式实现数据的查询,但是在界面显示的时候需要进行分页,接下来和大家分享一下,这个功能点是怎么实现的。
HTML
<table id="dg" class="easyui-datagrid"title="累积审核" style="width:75%;height:500px;"url="/AccumulateEvaluation/LoadPage" data-options="singleSelect:true,pagination:true,fitColumns:true,sortName:'itemid',sortOrder:'desc'" >
<thead>
<tr>
<th data-options="field:'departmentName'" style="width: 8px" align="center">上传的类型</th>
<th data-options="field:'accumulateStates'" style="text-align: right; width: 8px" align="center">处理结果</th>
<th data-options="field:'accumulateDescription'" style="width: 10px" align="center">描述</th>
<th data-options="field:'userName'" style="text-align: right; width: 10px" align="center">上传者</th>
<th data-options="field:'userID'" style="width: 10px" align="center" hidden>上传者ID</th>
<th data-options="field:'date'" style="width: 10px" align="center">上传时间</th>
</tr>
</thead>
</table>
D层
public List<accumulateModel> LoadPage(int pageSize, int pageIndex,out int total)
{
//查询总记录.ToList();
total = DBcontext.t_accumulate.Count();
//分页查询t_accumulate
List<accumulateModel> accumulatelist = new List<accumulateModel>();
accumulatelist = (from a in DBcontext.t_accumulate
join d in DBcontext.t_department on a.departmentID equals d.departmentID
join u in DBcontext.t_user on a.userID equals u.userID
where (a.accumulateStates.Contains("未审核"))
select new accumulateModel()
{
accumulateDescription = a.accumulateDescription,
accumulateStates = a.accumulateStates,
departmentName = d.departmentName,
userName = u.userName,
userID=u.userID,
date =a.date
}).OrderBy(p => p.date).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
return accumulatelist;
}