当我运行 View 时,它仅以这样的 JSON 格式显示
{“总计”:1,“页”:1,“记录”:4,“行”:[{“id”:2,“单元格”:[“fsff”,“fsfs”,“2” ]},{"id":3,"cell":["fsff","fsfs45","3"]},{"id":5,"cell":["shah","krutika","5"]},{"id":6,"cell":["1235","krutik","6"]}]}
我的代码是这样的: 查看:
<html>
<head>
<script src="~/Scripts/jquery-2.2.0.js"></script>
<script src="~/Scripts/jquery-ui-1.11.4.js"></script>
<script src="~/Scripts/jquery.jqGrid.min.js"></script>
<script src="~/Scripts/i18n/grid.locale-en.js"></script>
<link href="~/Content/jquery.jqGrid/ui.jqgrid.css" rel="stylesheet" />
<link href="~/Content/themes/base/all.css" rel="stylesheet" />
<script type="text/javascript">
$(document).ready(function myfunction() {
$('#list').jqGrid({
caption: "Employee Details",
url: '/Default1/grid/',
datatype: "json",
contentType: "application/json; charset-utf-8",
mtype: 'GET',
colNames: ['Address', 'Name'],
colModel: [
{ name: 'address', index: 'address', width: 150 },
{ name: 'name', index: 'name', width: 150 }
],
pager: "#pager",
rowNum: 10,
rowList: [10, 20, 30],
sortname: "invid",
sortorder: "desc",
viewrecords: true,
gridview: true,
autoencode: true,
caption: "My first grid"
});
jQuery("#list").jqGrid('navGrid', '#pager', { edit: true, add: true, del: true });
});
</script>
</head>
<body>
<table id="list"><tr><td></td></tr></table>
<div id="pager"></div>
</body>
</html>
在 Controller 中:
public JsonResult grid()
{
employeeDBEntities entity= new employeeDBEntities();
emp e1=new emp();
var jsondata=new{
total=1,
page=1,
records=entity.emps.ToList().Count,
rows = (
from emp in entity.emps.ToList()
select new
{
id = emp.id,
cell = new string[] {
emp.address.ToString(), emp.name.ToString(),emp.id.ToString()
}
}).ToArray()
};
return Json(jsondata,JsonRequestBehavior.AllowGet);
}
最佳答案
Always load css first because js files use those css
.这是应该的顺序。
<link href="~/Content/themes/base/all.css" rel="stylesheet"/>
<link href="~/Content/jquery.jqGrid/ui.jqgrid.css" rel="stylesheet" />
<script src="~/Scripts/jquery-2.2.0.js"></script>
<script src="~/Scripts/jquery-ui-1.11.4.js"></script>
<script src="~/Scripts/jquery.jqGrid.min.js"></script>
<script src="~/Scripts/i18n/grid.locale-en.js"></script>
关于javascript - json数据不显示在asp.mvc中的jqgrid formate中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35254472/