我正在尝试在我们的 MVC3 项目中实现 jqgrid。但是我遇到了这个错误: -
Microsoft JScript 运行时错误:“b.jgrid.errors.model”为空或不是对象。
这些是 _layout.cshtml 中引用的脚本:-
<script src="@Url.Content("~/Scripts/jquery-1.7.2.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-1.5.2.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/grid.local-en.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.jqGrid.min.js")" type="text/javascript"></script>
我的控制器代码如下所示:-
public ActionResult getSummaryRow(string sidx, string sord, int page, int rows)
{
int pageIndex = Convert.ToInt32(page) - 1;
int pageSize = rows;
int totalRecords = _context.Sales_Dashboard_summary.Where(a=>a.DateId==_dateid).Count();
int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
var summaryRecord = _context.Sales_Dashboard_summary.Skip(pageIndex * pageSize).Take(pageSize);
var jsonData = new
{
total = totalPages,
page,
records = totalRecords,
rows = (
from sRec in _context.Sales_Dashboard_summary
where sRec.DateId == _dateid
select new
{
i = sRec.DateId,
cell = new string[] { sRec.DateId.ToString(),
sRec.ReportName,
sRec.Month,
sRec.tot_msr_cnt.ToString(),
sRec.Missing_Count.ToString(),
sRec.PubInd
}
}
).ToArray()
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
这是我的查看页面:-
<script type="text/javascript">
$(function () {
$("#list").jqGrid({
url: '/Home/getSummaryRow/',
datatype: 'json',
mtype: 'GET',
colNames: ['Date Id','Report Name', 'Month', 'Total Measure','Missing Measure','Published'],
colModel: [
{ name: 'DateId', index: 'DateId', width: 20, align: 'left' },
{ name: 'ReportName', index: 'ReportName', width: 40, align: 'left' },
{ name: 'Month', index: 'Month', width: 40, align: 'left' },
{ name: 'tot_msr_cnt', index: 'tot_msr_cnt', width: 20, align: 'right' },
{ name: 'missing_count', index: 'missing_count', width: 20, align: 'right'}],
pager: jQuery('#pager'),
rowNum: 10,
rowList: [5, 10, 20, 50],
sortname: 'Month',
sortorder: "desc",
viewrecords: true,
imgpath: '/scripts/themes/coffee/images',
caption: 'Sales Dashboard'
});
});
</script>
<h2>@ViewBag.Message</h2>
<p>
<table id="list" class="scroll" cellpadding="0" cellspacing="0"></table>
<div id="pager" class="scroll" style="text-align:center;"></div>
</p>
提前致谢。