我有2个视图,首先是显示jquery网格的索引。 第二个是入口页面Customer 插入后我再次重定向到控制器中的Index(),但是没有显示onload网格,下面是网格的jquery函数 JqueryGrid代码
<script type="text/javascript">
$(document).ready(function () {
Search();
});
function Search() {
var jqDataUrl = "QueueMgmt/LoadData";
var reportName = "WallBoard";
$("#jqTable").jqGrid({
url: jqDataUrl,
datatype: "json",
mtype: "POST",
postData: { },
colNames: ["QUEUE", "CIQ", "Avail", "Staff"],
colModel: [
{ name: "QUEUE_NO", index: "QUEUE_NO", align: "left" },
{ name: "CIQ", index: "CIQ", align: "left" },
{ name: "Avail", index: "Avail", align: "left" },
{ name: "Staff", index: "Staff", align: "left" }
],
autowidth: true,
viewrecords: true,
sortname: "QUEUE_NO",
sortorder: "asc",
caption: reportName,
onSelectRow: function (id) {
rowSelected(id);
}
});
$("#jqTable").parents('div.ui-jqgrid-bdiv');
}
</script>
控制器代码:
public ActionResult LoadData(string sidx, string sord, int page, int rows)
{
try
{
// Get the list
var configs = MMDataprocess.Select().AsQueryable();
var filteredconfigs = configs;
// Sort the list
var sortedConfigs = SortIQueryable<QueueMgmtModel>(filteredconfigs, sidx, sord);
// Calculate the total number of pages
var totalRecords = filteredconfigs.Count();
var totalPages = (int)Math.Ceiling((double)totalRecords / (double)rows);
// Prepare the data to fit the requirement of jQGrid
var data = (from s in sortedConfigs
select new
{
id = s.QUEUE_NO,
cell = new object[] {s.QUEUE_NO,s.CIQ,s.Avail,s.Staff}
}).ToArray();
// Send the data to the jQGrid
var jsonData = new
{
total = totalPages,
page = page,
records = totalRecords,
rows = data.Skip((page - 1) * rows).Take(rows)
};
return Json(jsonData);
}
catch (Exception ex)
{
}
return null;
}
由于我是MVC新手,请帮我解决这个问题。
答案 0 :(得分:0)
在控制器返回语句中使用bellow
return Json(jsonData,JsonRequestBehavior.AllowGet);