我一直在遵循教程在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