【发布时间】:2016-08-01 09:49:15
【问题描述】:
我是 Web API 新手。
我在对话框模块中使用了 JQ 网格。
$(document).ready(function () {
$('.viewIcon').click(function () {
$(function () {
$("#jqtable").dialog({
title: "Admin Console",
resizable: false,
modal: true,
width: 'auto',
appendTo: "form",
open: function (event, ui) {
jQuery("#jQGridDemo").jqGrid({
url: 'api/AdminConsole/GetListDetailData',
datatype: "json",
colNames: ['Key', 'Value'],
colModel: [
{ name: 'Key', index: 'Key', width: 200, align: "right" },
{ name: 'Value', index: 'Value', width: 200, align: "right" },
],
jsonReader: {
repeatitems: false,
page: function () { return 1; },
root: function (obj) { return obj; },
records: function (obj) { return obj.length; }
},
pager: "#jqGridPager"
});
},
//buttons: {
// "Save": function () {
// $(this).dialog("close");
// },
// "Cancel": function () {
// $(this).dialog("close");
// }
//}
});
});
});
});
$("#jqtable").dialog("open");
我的个性
public List<DTO.ListDetailDTO> GetListDetailForListTpe(int type)
{
List<DTO.ListDetailDTO> allList = new List<DTO.ListDetailDTO>();
using (AspNetEntities context = new AspNetEntities())
{
allList = (from list in context.ListDetails
select new DTO.ListDetailDTO
{
Key = list.ListValue,
Value = list.ListKey
}).ToList();
}
return allList;
}
我的网络 API
[HttpGet()]
[ActionName("GetListDetailData")]
public Object GetListDetailData(bool _search,string sidx, string sord, int page, int rows)
{
int ListTpe = 1;
List<DTO.ListDetailDTO> list = new List<DTO.ListDetailDTO>();
ListManagementEntity listMgmt = new ListManagementEntity();
list = listMgmt.GetListDetailForListTpe(ListTpe);
var pageIndex = Convert.ToInt32(page) - 1;
var pageSize = rows;
var totalRecords = list.Count();
var totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
var jsonData = new
{
total = totalPages,
page = page,
records = totalRecords,
rows = JsonConvert.SerializeObject(list)
};
return jsonData;
}
我的 JQ 网格不显示任何内容。
【问题讨论】:
-
您是否验证了仅调用 'api/AdminConsole/GetListDetailData' 会返回数据?您是否在控制台中收到任何错误?
-
控制台没有错误。但显示空网格。