【積分系統】--Linq表示式實現分頁
阿新 • • 發佈:2019-02-03
【前言】
最近小編在專案中需要通過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;
}