//jqgrid工具类
public class JqgridData<T>
{
//list转成jqgird<list>
public Model.Jqgrid.JqgridDataModel<T> GetJqgridData(int initPage,int initRowNum, int record,IList<T> list)
{
return new Model.Jqgrid.JqgridDataModel<T>
{
page = initPage,
records = record,
total = (record % initRowNum) == 0 ? record / initRowNum : (record / initRowNum) + 1,
rows = list.Skip((initPage - 1) * initRowNum).Take(initRowNum).ToList()
};
}
}
调用
//获取所有检验员并分页
public JsonResult FindInspector()
{
//数据
var list = new BLL.Inspector_BLL().FindInspector();
//总数
var record = list.Count();
//初始化页码
var initPage = Convert.ToInt32(Request.Form["page"]);
//初始化每页显示数
var initRowNum = Convert.ToInt32(Request.Form["rows"]);
var jqgridDatas = new Helper.JqgridData.JqgridData<Model.WindFramSystem.Management_Inspector>().GetJqgridData(initPage, initRowNum, record, list);
return Json(jqgridDatas, JsonRequestBehavior.AllowGet);
}