我已经很努力了,但我没有得到任何成功。
我的控制器是
public ActionResult CompOff()
{
return View();
}
[HttpPost]
public JsonResult CompOff(RegisterCompOff r)
{
var compoffs = db.RegisterCompOffs.Where(l => l.Employee.Id == this.EmployeeId).Select(l => new { l.CompOffDate, l.Description, l.ExpiryDate, l.IsApproved, l.IsUtilized }).ToList();
return Json(compoffs);
}
我的看法是
<table id="jqgProducts" cellpadding="0" cellspacing="0"></table>
<div id="jqgpProducts" style="text-align:center;"></div>
<script src="@Url.Content("~/Scripts/jquery.jqGrid.min.js")" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#jqgProducts').jqGrid({
//url from wich data should be requested
url: '@Url.Action("CompOff")',
//type of data
datatype: 'json',
//url access method type
mtype: 'POST',
//columns names
colNames: ['CompOffDate', 'Description', 'ExpiryDate', 'IsApproved', 'IsUtilized'],
//columns model
colModel: [
{ name: 'CompOffDate', index: 'CompOffDate', align: 'left' },
{ name: 'Description', index: 'Description', align: 'left' },
{ name: 'ExpiryDate', index: 'ExpiryDate', align: 'left' },
{ name: 'IsApproved', index: 'IsApproved', align: 'left' },
{ name: 'IsUtilized', index: 'IsUtilized', align: 'left' }
],
//pager for grid
pager: $('#jqgpProducts'),
//number of rows per page
rowNum: 10,
//initial sorting column
sortname: 'CompOffDate',
//initial sorting direction
sortorder: 'asc',
//we want to display total records count
viewrecords: true,
//grid height
height: '100%'
});
});
</script>
我在我的控制器的 post 方法中得到 json 结果,但数据没有绑定到我的网格..我看到的是一个空网格,当我尝试绑定一些本地数据时,它工作得很好,可以有人吗请帮助我