Hi i got a simple actinReault which return jsonResult. The method is following.
[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 data on AllEmpObjects which is coming form DB
"[{\\"FirstName\\":\\"shuvo\\",\\"LastName\\":\\"ahmed\\",\\"Address1\\":\\"110, uttra\\",\\"Address2\\":\\"mymansing\\",\\"HomePhone\\":1234,\\"MobileNo\\":2345,\\"Email\\":\\"suvo@yahoo.com\\",\\"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\\"}]
My JS file which is responsible to show 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 on output but the grid appears with empty inside. can anyone help please?
You should remove the line
var AllEmpObjects= JsonConvert.SerializeObject(employeesViewMod);
from your code and replace return Json(AllEmpObjects);
to
return Json(employeesViewMod);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.