【发布时间】:2017-08-01 12:26:09
【问题描述】:
我正在使用 Trirand 的 jqGrid。网格标题、行、分页正确显示,但未填充数据行。我浏览了很多帖子并尝试了很多解决方案,但它根本行不通。我确定缺少一些非常简单的东西,但我无法弄清楚。
我从我的 ASP.NET MVC 控制器收到以下响应:
{ “总计”:1,“页面”:1,“记录”:2,“行”:[ { "Id":"1", "StudentName":"Student1" }, { "Id":"2", "StudentName":"Student2" } ] }
而jqGrid代码如下:
$(function () { $("#jqGrid").jqGrid({ url: '/Home/GetStudentsLists', dataType: "json", mtype: 'GET', colNames: ['Id', 'StudentName'], colModel: [ { name: 'Id', index: 'Id', width: 60 }, { name: 'StudentName', index: 'StudentName', width: 60 } ], rowNum: 9999, sortname: 'Id', loadonce: true, rowList: [10, 20, 30], pager: '#jqpager', viewrecords: true, sortorder: "desc", caption: "Students Details", height: 100, autowidth: true }) });
包含脚本标签的布局页面如下所示:
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My ASP.NET Application</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>
<body>
...
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
<link href="~/Content/themes/base/jquery-ui.css" rel="stylesheet" />
<link href="~/Content/jquery.jqGrid/ui.jqgrid.css" rel="stylesheet" />
<script src="~/Scripts/jquery-ui-1.10.0.js"></script>
<script src="~/Scripts/i18n/grid.locale-en.js"></script>
<script src="~/Scripts/jquery.jqGrid.js"></script>
<script src="~/Scripts/Custom/jQGridStudents.js"></script>
</body>
感谢您的帮助。
【问题讨论】:
-
您使用(或可以使用)jqGrid 的哪个 版本 以及 jqGrid 的哪个 fork(free jqGrid、商业 Guriddo jqGrid JS 或dataType: "json" 修复为
datatype: "json"。这应该是你的主要问题。您代码中的其他建议取决于您使用的 jqGrid 的版本和分支。 -
非常感谢。我正在使用 Trirand 的 jquery.jqGrid,版本 4.4.4 和 nuget 上提供的 jquery 版本 3.1.1,我可以使用您提到的任何这些网格。其次,我认为您在评论中已经写了两次 dataType: "json" 。参见上面的文本 [dataType: "json" to dataType: "json"]。
-
JavaScript 区分大小写,
datatype与dataType不一样(带有大写字母T)。 4.4.4 版本已经 4.5 年了,已经死了很久了。如果你使用 NuGet,那么我建议你卸载旧包并使用free-jqGrid。或者,我建议您考虑从 CDN 加载免费的 jqGrid。见here 和here。 -
谢谢奥列格!它确实奏效了。
标签: asp.net-mvc-4 jqgrid