jqGrid无法加载数据

时间:2014-11-06 13:14:02

标签: javascript c# jqgrid

您好我有一个简单的actinReault返回jsonResult。方法如下。

[HttpPost]
    public  JsonResult AllEmployees()
    {
        EmployeeService employeeService = new EmployeeService();
        List<EmployeeViewModel> employeesViewMod = employeeService.allEmployee();
        var AllEmpObjects= JsonConvert.SerializeObject(employeesViewMod); 
        return Json(AllEmpObjects);
    }

我们可以调试和查看来自DB

的AllEmpObjects上的数据
  

“[{\”FirstName \“:\”shuvo \“,\”LastName \“:\”ahmed \“,\”Address1 \“:\”110,uttra \“,\”Address2 \“: \ “mymansing \”,\ “HOMEPHONE \”:1234,\ “MobileNo \”:2345,\ “电子邮件\”:\ “suvo@yahoo.com \”,\ “杜伯\”:\“10/01 / 1977年\ “\ ”开始日期\“:\ ”2013-10-01T00:00:00 \“,\ ”InitialSalary \“:0,\ ”AccHolderName \“:空,\ ”BANKNAME \“:\” 布拉奇\ ” \ “早午餐\”:\ “uttra \”,\ “AccountNo \”:1234567890,\ “PositionDDLId \”:0,\ “MarriageStatDDLId \”:0,\ “PositionIdString \”:\ “MD \”, \ “MarriageIdString \”:\ “已婚\”}]

我的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",
}); 

}

遗憾的是,输出中没有数据,但网格内部显示为空。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:3)

您应该删除该行

var AllEmpObjects= JsonConvert.SerializeObject(employeesViewMod);

从您的代码中将return Json(AllEmpObjects);替换为

return Json(employeesViewMod);