嗨,我有一个简单的 actinReault,它返回 jsonResult。方法如下。
[HttpPost]
public JsonResult AllEmployees()
{
EmployeeService employeeService = new EmployeeService();
List<EmployeeViewModel> employeesViewMod = employeeService.allEmployee();
var AllEmpObjects= JsonConvert.SerializeObject(employeesViewMod);
return Json(AllEmpObjects);
}
我们可以调试并查看来自数据库的 AllEmpObjects 数据
"[{\"FirstName\":\"shuvo\",\"LastName\":\"ahmed\",\"Address1\":\"110, uttra\",\"Address2\":\"mymansing\",\"HomePhone\":1234,\"MobileNo\":2345,\"Email\":\"[email protected]\",\"Dob\":\"10/01/1977\",\"StartDate\":\"2013-10-01T00:00:00\",\"InitialSalary\":0,\"AccHolderName\":null,\"BankName\":\"brac\",\"Brunch\":\"uttra\",\"AccountNo\":1234567890,\"PositionDDLId\":0,\"MarriageStatDDLId\":0,\"PositionIdString\":\"Md\",\"MarriageIdString\":\"Married\"}]
我的 JS 文件负责使用 jqGrid 显示数据:
function allEmployeeFunc() {
$("#list").jqGrid({
url: "/Employee/AllEmployees",
datatype: "json",
mtype: "POST",
colNames: ["First name", "Last Name", "phone", "Mobile", "Email", "status"],
colModel: [
{ name: "FirstName", width: 55 },
{ name: "LastName", width: 90 },
{ name: "HomePhone", width: 80, align: "right" },
{ name: "MobileNo", width: 80, align: "right" },
{ name: "Email", width: 80, align: "right" },
{ name: "MarriageIdString", width: 150, sortable: false }
],
pager: "#pager",
rowNum: 10,
rowList: [10, 20, 30],
sortname: "invid",
sortorder: "desc",
viewrecords: true,
gridview: true,
autoencode: true,
caption: "Detail of all EMPLOYEE",
});
}
不幸的是,输出中没有数据,但网格显示内部为空。有人可以帮忙吗?
最佳答案
您应该删除该行
var AllEmpObjects= JsonConvert.SerializeObject(employeesViewMod);
从您的代码中并将 return Json(AllEmpObjects);
替换为
return Json(employeesViewMod);
关于javascript - jqGrid 无法加载数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26780431/