jqGrid的不显示JSON数据 [英] JQGrid not showing json data
本文介绍了jqGrid的不显示JSON数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我跟这个很努力,但我没有收到任何与它的成功。
I have tried hard with this but i'm not getting any success with it.
我的控制器是
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>
我得到JSON结果在我的控制器的POST方法,但该数据没有得到绑定到我的grid..all我看到是一个空格,当我尝试绑定一些地方的数据,它的工作好,可有一个人,请帮助我在此
I'm getting json result in post method of my controller but that data is not getting binded to my grid..all i'm seeing is an empty grid, when i try to bind some local data, it works good, can some one please help me on this
推荐答案
您必须以正确的格式提供必要的参数,返回JSON数据。
You have to return the JSON data in the proper format with the necessary parameters.
有关前。
return Json(new{
total = 1,
page = 1,
records = collection.Count, // actual data count
rows = collection // actual data
});
您未在总
,页
(当前页),记录<返回/ code>和
行
。
You are not returning the total
, page
(current page), records
and rows
.
试试这个..
[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(new{
total = 100, // change into actual value
page = 1, //first page
records = compoffs.Count(), // no. of records you are returning now
rows = compoffs // data
});
}
和添加以下部分,查看
jsonReader : {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false,
cell: "cell",
id: "id",
userdata: "userdata",
},
这篇关于jqGrid的不显示JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文