我的 .cshtml 如下:
<script type="text/javascript">
$(function () {
$("#list").jqGrid({
url: '/LogInManagement/DisplayItems/',//this is action in controller which returns the json as result.
datatype: 'json',
mtype: 'GET',
colNames: ['ID', 'Product Name', 'Description', 'IsInStock', 'Attachment'],//column name
colModel: [
{ name: 'ID', index: 'Id', width: 40, align: 'left' },
{ name: 'ProductName', index: 'ProductName', width: 240, align: 'left' },
{ name: 'Description', index: 'Description', width: 200, align: 'left' },
{ name: 'IsInStock', index: 'IsInStock', width: 40, align: 'left' },
{ name: 'Attachment', index: 'Attachment', width: 240, align: 'left' }],
pager: jQuery('#pager'),
rowNum: 10,
rowList: [5, 10, 20, 50],
sortname: 'Id',
sortorder: "desc",
viewrecords: true,
caption: 'Items'
});
});
</script>
@{
ViewBag.Title = ViewBag.DisplayName;
}
<h2>Welome : @ViewBag.DisplayName</h2>
<table id="list" class="scroll" cellpadding="0" cellspacing="0"></table>
<div id="pager" class="scroll" style="text-align:center;"></div>
我正在调用方法“DisplayItems”,如下所示:
public ActionResult DisplayItems()
{
Item item = new Item();
int pages = 0;
var resultItems = Assignment.Models.Item.GetItems().ToArray();
var jsonData = new
{
total = 1,
page = pages,
records = resultItems.Count(),
rows = resultItems
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
它正在正确返回数据。但是cshtml中的网格显示“正在加载...”,但没有数据。数据采用以下格式: