Hey there, I have a simple action result that returns a JsonResult. Here is the method:
[HttpPost]
public JsonResult AllEmployees()
{
EmployeeService employeeService = new EmployeeService();
List<EmployeeViewModel> employeesViewMod = employeeService.allEmployee();
var AllEmpObjects= JsonConvert.SerializeObject(employeesViewMod);
return Json(AllEmpObjects);
}
We can debug and see the data on AllEmpObjects which is coming from the database.
"[{\"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\"}]
Here is my JavaScript file that is responsible for displaying data using 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",
});
}
Unfortunately, there is no data appearing in the output, only the grid displays empty inside. Can anyone please help?