我一直在遵循教程在https://tpeczek.codeplex.com/獲取jqGrid工作和更新我的GetData()actionresult以啓用分頁和排序,現在我的網格不再顯示數據,但我不知道爲什麼沒有錯誤拋出拋出。代碼曾經工作:jqGrid不顯示數據,但分頁和列名顯示/工作正常
public ActionResult GetData()
{
try
{
var model = (from s in db.Sections
select new
{
s.ID,
s.RouteName,
s.Title
}).ToList();
return Json(model, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
ErrorSignal.FromCurrentContext().Raise(ex);
return Json(null, JsonRequestBehavior.AllowGet);
}
}
我的新代碼試圖添加分頁和排序。
公共的ActionResult的GetData(字符串SIDX,串SORD,INT頁,INT行) { 嘗試 { INT行數= db.Sections.Count(); int SkipCount =(page * rows);
string OrderBy = (sidx + " " + sord);
var SectionData = new
{
total = (int)Math.Ceiling((float)RowCount/(float)rows),
page = page,
records = RowCount,
rows = (from s in db.Sections
select new
{
id = s.ID,
cell = new string[] {
SqlFunctions.StringConvert((double)s.ID).Trim(),
s.RouteName,
s.Title
}
.OrderBy(x => sidx)
.Skip(SkipCount)
.Take(rows)
}).ToArray()
};
return Json(SectionData, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
ErrorSignal.FromCurrentContext().Raise(ex);
return Json(null, JsonRequestBehavior.AllowGet);
}
}
編輯: 的jqGrid代碼:
<script type="text/javascript">
$(document).ready(function()
{
$('#Sections').jqGrid({
url: '/Admin/Section/GetData',
datatype: 'json',
mtype: 'GET',
colNames: ['ID', 'RouteName', 'Title'],
colModel: [
{ name: 'ID', index: 'ID', width: '10' },
{ name: 'RouteName', index: 'RouteName', width: '50' },
{ name: 'Title', index: 'Title' }
],
autowidth: true,
height: '100%',
pager: $('#SectionsPager'),
rowNum: 10,
sortname: 'ID',
sortorder: 'asc',
viewrecords: true
}).navGrid(
'#SectionsPager',
//enabling buttons
{ add: true, del: false, edit: false, search: false },
//edit options
{ width: 'auto' },
//add options
{ width: 'auto', url: '/Admin/Section/Add' },
//delete options
{});
});
@ Eagle..please爲jqgrid..there顯示的代碼可能是錯誤 –
@Avinash對此感到遺憾被衝出工作,忘了。我現在添加了它。 – Matthew