0
我在使用mvc的jqgrid中遇到服務器端分頁問題。這是我的控制器代碼。如何解決JQGrid中使用mvc4的服務器端分頁問題
[HttpGet]
public JsonResult GetAllStudents(JqGridRequest jRequest) {
var Records = from a in entities.studentdetails.ToList() select new {
a.ID,
a.Name,
a.DOB
};
int pageIndex = Convert.ToInt32(jRequest.PageIndex);
int pageSize = jRequest.RecordsCount;
int startRow = (pageIndex * pageSize) + 1;
int totalRecords = Records.Count();
int totalPages = (int)Math.Ceiling((float)totalRecords/(float)pageSize);
Records = Records.Skip(pageIndex * pageSize).Take(pageSize).ToArray();
if (jRequest.Searching) {
int sId = Convert.ToInt32(jRequest.SearchingFilters.Filters[0].SearchingValue);
//string sName = jRequest.SearchingFilters.Filters[0].SearchingValue;
Records = entities.studentdetails.Select(a => new {
a.ID,
a.Name,
a.DOB
}).Where(p => p.ID == sId);
}
else {
Records = entities.studentdetails.Select(a => new {
a.ID,
a.Name,
a.DOB
});
}
var jsonData = new {
total = totalPages,
page = pageIndex,
records = totalRecords,
rows = Records
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
*「與服務器端分頁我現在面臨的問題......」 * - 你應該說明是什麼問題。 – jww