本文介绍了JqGrid使用jquery和jsonresult的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! iam使用jqgrid使用json结果但是网格没有填充plz帮助我 这里是我的代码 控制器: public JsonResult GetEmployeeData() { List< models.empdetails> emp = new List< models.empdetails>(); con.Open(); string query = 从EmpDetail中选择*其中StatusTypeId = EmpId DESC的1个订单; SqlCommand cmd = new SqlCommand(query,con); SqlDataAdapter da = new SqlDataAdapter(cmd); cmd.CommandType = CommandType.Text; DataSet ds = new DataSet(); da.Fill(ds); foreach (DataRow dr in ds.Tables [ 0 ]。行) { emp.Add( new Models.EmpDetails() { Name = dr [ 0 ]。ToString(), EmpId = Convert.ToInt32(dr [ 1 ]。ToString()), Salary = Convert.ToInt32(dr [ 2 ]。ToString()),地址= dr [ 3 ]。ToString(), ZipCode = Convert.ToInt32(dr [ 4 ]。ToString()), PhoneNumber = Convert.ToInt32(dr [ 5 ]。ToString()), Permanent = Boolean .Parse(dr [ 7 ]。ToString() ), Birthday = Convert.ToDateTime(dr [ 8 ]。ToString()), Country = dr [ 9 ]。ToString()}); } cmd.ExecuteNonQuery(); return Json(emp,JsonRequestBehavior.AllowGet); } jquery: $(document).ready(function(){ $(' #grd')。jqGrid( { dataType:' json', height: 250 , mtype:' 获取', url: ' / Home / GetEmployeeData', colNames:[' 名称',' 地址',' 薪水',' PhoneNumber',' Zipcode',' Permanent',' 生日',' 国家'], colModel:[{name:' 名称',索引: ' 名称',宽度: 80 }, {name:' 地址',索引:' 地址',宽度: 100 }, {name: ' 薪水',索引:' 薪水',width: 60 }, {name:' PhoneNumber',index:' PhoneNumber',width: 75 }, {name:' ZipCode',index:' ZipCode',width: 75 }, {name:' Permanent',index:' Permanent',width: 60 }, {name:' Birthday',index:' 生日',宽度: 75 }, {name:' Country',index:' Country',width: 100 } ], cation:' EmplyoeeDetails', pager:$(' #pager'), sortdesc:' desc', viewrecords: true }); }); 解决方案 (' #grd')。jqGrid( { dataType: ' json', height: 250 , mtype:' 获取', url:' / Home / GetEmployeeData', colNames:[ ' 名称',' 地址',' 薪水',' PhoneNumber',' Zi pcode',' Permanent',' 生日',' 国家'], colModel:[{name:' 名称',索引:' 名称',宽度: 80 }, {名称:' 地址',索引: ' 地址',宽度: 100 }, {name:' 薪水',索引:' 薪水',宽度: 60 }, {n ame:' PhoneNumber',index:' PhoneNumber',width: 75 }, {name:' ZipCode',index:' ZipCode',width: 75 }, {name:' 永久',索引:' Permanent',width: 60 }, {name:' Birthday',index:' 生日',宽度: 75 }, {name:' Country',index:' Country',width: 100 } ], cation:' EmplyoeeDetails', pager: Hi, iam using jqgrid using json result but grid is not populating plz help mehere is my codefor controller:public JsonResult GetEmployeeData() { List<models.empdetails> emp = new List<models.empdetails>(); con.Open(); string query = "select * from EmpDetail where StatusTypeId=1 order by EmpId DESC"; SqlCommand cmd = new SqlCommand(query, con); SqlDataAdapter da = new SqlDataAdapter(cmd); cmd.CommandType = CommandType.Text; DataSet ds = new DataSet(); da.Fill(ds); foreach (DataRow dr in ds.Tables[0].Rows) { emp.Add(new Models.EmpDetails() { Name = dr[0].ToString(), EmpId = Convert.ToInt32(dr[1].ToString()), Salary = Convert.ToInt32(dr[2].ToString()), Address = dr[3].ToString(), ZipCode = Convert.ToInt32(dr[4].ToString()), PhoneNumber = Convert.ToInt32(dr[5].ToString()), Permanent = Boolean.Parse(dr[7].ToString()), Birthday = Convert.ToDateTime(dr[8].ToString()), Country = dr[9].ToString() }); } cmd.ExecuteNonQuery(); return Json(emp, JsonRequestBehavior.AllowGet); }jquery:$(document).ready(function () { $('#grd').jqGrid( { dataType: 'json', height: 250, mtype: 'Get', url: '/Home/GetEmployeeData', colNames: ['Name', 'Address', 'Salary', 'PhoneNumber', 'Zipcode', 'Permanent', 'Birthday', 'Country'], colModel: [{ name: 'Name', index: 'Name', width: 80 }, { name: 'Address', index: 'Address', width: 100 }, { name: 'Salary', index: 'Salary', width: 60 }, { name: 'PhoneNumber', index: 'PhoneNumber', width: 75 }, { name: 'ZipCode', index: 'ZipCode', width: 75 }, { name: 'Permanent', index: 'Permanent', width: 60 }, { name: 'Birthday', index: 'Birthday', width: 75 }, { name: 'Country', index: 'Country', width: 100 } ], cation: 'EmplyoeeDetails', pager: $('#pager'), sortdesc: 'desc', viewrecords: true }); }); 解决方案 这篇关于JqGrid使用jquery和jsonresult的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-14 10:45