【发布时间】:2017-01-04 08:51:02
【问题描述】:
在下面的代码中,动作方法GetData()将数据加载到jqgrid。但是有趣的是它显示它有数据但行没有显示数据,寻呼机组件显示它有多个页面,我可以单击行,当我单击一行时它甚至显示蓝色边框颜色但仍然没有显示数据.
我做了所有我能找到的问题,有没有办法解决这个问题?
动作方法:
DBContext db = new DBContext();
public ActionResult Index()
{
return View();
}
public JsonResult GetData()
{
try
{
var customers = db.Customers.Select(x => new { x.CustomerID, x.FirstName, x.MiddleName,x.CompanyName, x.SalesPerson, x.EmailAddress }).ToList();
return Json(customers, JsonRequestBehavior.AllowGet);
}
catch (Exception)
{
throw;
}
}
观点:
<script src="~/Scripts/jquery-3.1.0.js"></script>
<script src="~/Scripts/jquery-ui-1.12.0.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqgrid/4.6.0/js/i18n/grid.locale-en.js"></script>
<script src="~/Scripts/jquery.jqGrid.min.js"></script>
<h2>Index</h2>
<table id="customerGrid"></table>
<div id="pager1"></div>
@section scripts{
<script>
$(function () {
jQuery("#customerGrid").jqGrid({
url: 'Home/GetData',
datatype: "json",
mtype: "GET",
postData:'',
colNames: ['Customer ID', 'First Name', 'Last Name'],
colModel: [
{ name: 'customerid', index: 'CustomerID', key:true,sorttype:'int', width: 100 },
{ name: 'firstname', index: 'FirstName', width: 100 },
{ name: 'lastname', index: 'LastName', width: 100 }
],
viewrecords: true,
gridview: true,
autoencode: true,
loadonce: true, //if all data loaded at once
rowNum: 10,
rowList: [10, 20, 30],
pager: '#pager1',
sortname: 'customerid',
viewrecords: true,
sortorder: "desc",
caption: "Customer List",
width:600
});
jQuery("#customerGrid").jqGrid('navGrid', '#pager1', { edit: false, add: false, del: false });
})
</script>
}
【问题讨论】:
标签: jquery asp.net-mvc jqgrid