Jquery 从webservice返回有效的JSON数据,但未填充jqGrid
我有一个类,在我的Web服务中填充数据。它被称为JqGridData,它的灵感来源于Oleg对另一个线程的回应。看起来是这样的:Jquery 从webservice返回有效的JSON数据,但未填充jqGrid,jquery,json,jqgrid,Jquery,Json,Jqgrid,我有一个类,在我的Web服务中填充数据。它被称为JqGridData,它的灵感来源于Oleg对另一个线程的回应。看起来是这样的: public class JqGridData { /// <summary> /// The number of pages which should be displayed in the paging controls at the bottom of the grid. /// </summary>
public class JqGridData
{
/// <summary>
/// The number of pages which should be displayed in the paging controls at the bottom of the grid.
/// </summary>
public int Total { get; set; }
/// <summary>
/// The current page number which should be highlighted in the paging controls at the bottom of the grid.
/// </summary>
public int Page { get; set; }
/// <summary>
/// The total number of records in the entire data set, not just the portion returned in Rows.
/// </summary>
public int Records { get; set; }
/// <summary>
/// The data that will actually be displayed in the grid.
/// </summary>
public IEnumerable Rows { get; set; }
/// <summary>
/// Arbitrary data to be returned to the grid along with the row data. Leave null if not using. Must be serializable to JSON!
/// </summary>
public object UserData { get; set; }
}
但是,jqGrid中没有显示任何行。如果有人有一些想法,我们将不胜感激
另外,如果我将JqGridData的Rows字段更改为定义的类,如JqGridRecord,并返回这些字段的列表,那么一切都可以正常工作。但我不想被迫为我想要返回的所有特定返回数据组合定义类
已更新
只要我返回一个对象,它就可以正常工作。但我想阻止这种情况
JqGridData result = new JqGridData()
{
page = page,
total = (int)Math.Ceiling((decimal)totalCount / rows),
records = totalCount,
rows = (from order in orders
select new jqGridRecord
{
OrderId = order.OrderId//,
//OrderId = order.OrderId//,
//OrderStatusName = order.OrderStatusName,
//OrderDate = order.ActionDate.Value.Date.ToShortDateString(),
//OrderTypeName = order.OrderTypeName,
//OrderPhoneNo = order.PhoneNo,
//OrderProductName = order.Product.ProductName,
//OrderTempNumber = order.TempNumber,
//OrderLines = order.FormattedOrderlines
}).ToList()//,
//UserData = o
};
return result;
您是否可以通过类似于以下内容的方式将数据返回到jqGrid:
...
var jsonData = new
{
total = (totalRecords + rows - 1) / rows,
page = page,
records = totalRecords,
rows = (
from temp in pagedQuery.ToList()
select new
{
cell = new string[] {
temp.item1,
temp.item2,
...
}
}).ToArray()
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
现在我的JSON看起来是这样的:{“总计”:73,“页面”:1,“记录”:2179,“行”:[{“单元格”:[“30903”]},{“单元格”:[“30852”]},…]},但我的jqGrid仍然没有填充。@schliemann尝试删除
contentType:'application/JSON;charset=utf-8',
不带contentType的事件:'application/json;charset=utf-8“未加载任何数据。我已更新了我的初始问题。尽管这并不能真正解决我的问题。
{"Total":73,"Page":1,"Records":2179,"Rows":[{"Id":30903,"OrderId":30903},{"Id":30852,"OrderId":30852},{"Id":30692,"OrderId":30692},{"Id":30687,"OrderId":30687},{"Id":30686,"OrderId":30686},{"Id":30684,"OrderId":30684},{"Id":30683,"OrderId":30683},{"Id":30682,"OrderId":30682},{"Id":30681,"OrderId":30681},{"Id":30680,"OrderId":30680},{"Id":30678,"OrderId":30678},{"Id":30677,"OrderId":30677},{"Id":30676,"OrderId":30676},{"Id":30675,"OrderId":30675},{"Id":30674,"OrderId":30674},{"Id":30673,"OrderId":30673},{"Id":30668,"OrderId":30668},{"Id":30667,"OrderId":30667},{"Id":30665,"OrderId":30665},{"Id":30664,"OrderId":30664},{"Id":30663,"OrderId":30663},{"Id":30647,"OrderId":30647},{"Id":30635,"OrderId":30635},{"Id":30411,"OrderId":30411},{"Id":30331,"OrderId":30331},{"Id":30330,"OrderId":30330},{"Id":30287,"OrderId":30287},{"Id":30241,"OrderId":30241},{"Id":30240,"OrderId":30240},{"Id":30239,"OrderId":30239}],"UserData":null}
JqGridData result = new JqGridData()
{
page = page,
total = (int)Math.Ceiling((decimal)totalCount / rows),
records = totalCount,
rows = (from order in orders
select new jqGridRecord
{
OrderId = order.OrderId//,
//OrderId = order.OrderId//,
//OrderStatusName = order.OrderStatusName,
//OrderDate = order.ActionDate.Value.Date.ToShortDateString(),
//OrderTypeName = order.OrderTypeName,
//OrderPhoneNo = order.PhoneNo,
//OrderProductName = order.Product.ProductName,
//OrderTempNumber = order.TempNumber,
//OrderLines = order.FormattedOrderlines
}).ToList()//,
//UserData = o
};
return result;
...
var jsonData = new
{
total = (totalRecords + rows - 1) / rows,
page = page,
records = totalRecords,
rows = (
from temp in pagedQuery.ToList()
select new
{
cell = new string[] {
temp.item1,
temp.item2,
...
}
}).ToArray()
};
return Json(jsonData, JsonRequestBehavior.AllowGet);