我需要将json
数据绑定到jqGridView
,但它会显示如下数据,
[{"name":"anita","qualification":"B.tech","login_id":null,"state":null},
{"name":"kavitha","qualification":"B.tech","login_id":null,"state":null},
{"name":"mounika","qualification":"B.tech","login_id":null,"state":null},
{"name":"radha","qualification":"M.tech","login_id":null,"state":null},
{"name":"JILLU","qualification":"B.tech","login_id":null,"state":null},
{"name":"divya","qualification":"MBA","login_id":null,"state":null},
{"name":"priya","qualification":"B.tech","login_id":null,"state":"andhra pradesh "},
{"name":"dhanwin","qualification":"B tech","login_id":null,"state":"karnataka "},
{"name":"dhanwin","qualification":"B tech","login_id":null,"state":"karnataka "},
{"name":"rakesh","qualification":"B tech","login_id":null,"state":"telagana "},
{"name":"rathode","qualification":"MBA","login_id":"rathode123","state":"karnataka "},
{"name":"erw","qualification":"","login_id":"","state":" "},
{"name":"","qualification":"","login_id":null,"state":" "},
{"name":"asdfsd","qualification":"fdg","login_id":null,"state":"hgjh "},
{"name":"saddfs","qualification":"sdfsg","login_id":null,"state":"gfhg "},
{"name":"saddfs","qualification":"sdfsg","login_id":null,"state":"gfhg "},
{"name":"saddfs","qualification":"sdfsg","login_id":null,"state":"gfhg "},
{"name":"saddfs","qualification":"sdfsg","login_id":null,"state":"gfhg "},
{"name":"saddfs","qualification":"sdfsg","login_id":null,"state":"gfhg "},
{"name":"","qualification":"","login_id":null,"state":" "},
{"name":"","qualification":"","login_id":null,"state":" "},
{"name":"","qualification":"","login_id":null,"state":" "},
{"name":"dfgdf","qualification":"dfgd","login_id":null,"state":"fdhg "},
{"name":"","qualification":"","login_id":null,"state":" "},
{"name":"sdaf","qualification":"fdg","login_id":null,"state":"dfgsdfgffffffff"},
{"name":"ty","qualification":"gfhgf","login_id":null,"state":"hgh "},
{"name":"ty","qualification":"gfhgf","login_id":null,"state":"hgh "},
{"name":"sdg","qualification":"fdgfd","login_id":null,"state":"ghg "},
{"name":"cbn","qualification":"bvn","login_id":null,"state":"nmbv "},
{"name":"cbn","qualification":"bvn","login_id":null,"state":"nmbv "},
{"name":"","qualification":"","login_id":null,"state":" "},
{"name":"","qualification":"","login_id":null,"state":" "},
{"name":"gfdgfsd","qualification":"ghfh","login_id":null,"state":" "},
{"name":"","qualification":"","login_id":null,"state":" "},
{"name":"","qualification":"","login_id":null,"state":" "},
{"name":"fhdgh","qualification":"gfdh","login_id":null,"state":" "},
{"name":"fhdgh","qualification":"gfdh","login_id":null,"state":" "},
{"name":"sfdfdf","qualification":"","login_id":null,"state":" "},
{"name":"sfdfdf","qualification":"","login_id":null,"state":" "},
{"name":"sadada","qualification":"","login_id":null,"state":" "},
{"name":"sadada","qualification":"","login_id":null,"state":" "},
{"name":"dsfadfasd","qualification":"","login_id":null,"state":" "},
{"name":"dsfadfasd","qualification":"","login_id":null,"state":" "},
{"name":"sadfs","qualification":"dsfdf","login_id":"sdfsgfdg","state":"fgdf "},
{"name":"sdffg","qualification":"jillu","login_id":"hhhhh","state":"jhkh "},
{"name":"sdffg","qualification":"jillu","login_id":"hhhhh","state":"jhkh "},
{"name":"dfdsg","qualification":"dsfgf","login_id":"hhhhj","state":"hhh "}]
这是我的控制器,
public JsonResult JqGrid()
{
var dbResult = db.registers.ToList();
var registers = (from reg in dbResult
select new
{
reg.name,
reg.qualification,
reg.login_id,
reg.state,
});
return Json(registers, JsonRequestBehavior.AllowGet);
}
这是我的观点,
@model IEnumerable<mvcComplte.Models.register>
@{
ViewBag.Title = "JqGrid";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@section styles
{
<link href="~/Content/themes/base/jquery-ui.css" rel="stylesheet" />
<link href="~/Content/jquery.jqGrid/ui.jqgrid.css" rel="stylesheet" />
<link rel="stylesheet" type="text/css" href="http://jqwidgets.com/jquery-widgets-demo/jqwidgets/styles/jqx.base.css" />
}
@section scripts
{
<script src="~/Scripts/i18n/grid.locale-en.js"></script>
<script src="~/Scripts/jquery.jqGrid.js"></script>
<script type="text/javascript">
$(document).ready(function () {
jQuery("#list").jqGrid({
url: 'Home/JqGrid',
datatype: "json",
colNames: ['name', 'qualification','state', 'login_id'],
colModel: [
{ name: 'name', width: 75 },
{ name: 'qualification', width: 150 },
{ name: 'state', width: 150 },
{ name: 'login_id', width: 150 },
],
gridview: true,
width: 750,
height: auto,
});
});
</script>
}
<h2>JqGrid</h2>
<table id="list"></table>
感谢任何帮助。