我正在使用jqGrid 4.5.4。我的ASP.NET MVC视图中有一个jqGrid javascript错误。 Visual Studio捕获错误:
无法获取未定义或空引用错误的属性“整数”
如果我在Javascript调试器中查看并查看视图,则会加载数据,但会显示一个未定义的框。
我已按照文档确认脚本已加载到视图/布局输出中。
我的观点:
@{
Layout = "~/Views/Shared/_Admin.cshtml";
}
<h2>Manage Posts, Categories and Tags</h2>
<div id="tabs">
<ul>
<li><a href="#tab-posts">Posts</a></li>
<li><a href="#tab-cats">Categories</a></li>
<li><a href="#tab-tags">Tags</a></li>
<li><a href="#tab-comments">Comments</a></li>
</ul>
<div id="tab-posts" class="tab">
<table id="tablePosts" class="grid">
</table>
<div id="pagerPosts" class="pager">
</div>
</div>
<div id="tab-cats" class="tab">
<table id="tableCats" class="grid">
</table>
<div id="pagerCats" class="pager">
</div>
</div>
<div id="tab-tags" class="tab">
<table id="tableTags" class="grid">
</table>
<div id="pagerTags" class="pager">
</div>
</div>
<div id="tab-comments" class="tab">
<table id="tableComments" class="grid">
</table>
<div id="pagerComments" class="pager">
</div>
</div>
</div>
我的布局文件的头部分(_Admin.cshtml)
<head>
<meta name="viewport" content="width=device-width" />
<title>Manage Posts, Categories and Tags</title>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")
<link href="../../Content/themes/simple/jquery-ui-1.10.4.custom.css" rel="stylesheet"
type="text/css" />
<link href="../../Scripts/ui.jqgrid.css" rel="stylesheet" type="text/css" />
<script src="../../Scripts/grid.locale-en.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.jqGrid.src.js" type="text/javascript"></script>
<link href="../../Content/themes/simple/simple.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="~/Scripts/admin.js"></script>
</head>
我的控制器方法:
[Authorize]
public ContentResult Posts(JQGridViewModel gridparams)
{
var posts = _postRepository.AdminPosts(gridparams.page - 1, gridparams.rows, gridparams.sidx, gridparams.sord == "asc");
var totalPosts = _postRepository.TotalPosts;
return Content(JsonConvert.SerializeObject(new
{
page = gridparams.page,
records = totalPosts,
rows = posts,
total = Math.Ceiling(Convert.ToDouble(totalPosts) / gridparams.rows)
}, new CustomDateTimeConverter()), "application/json");
}
public class CustomDateTimeConverter:Newtonsoft.Json.Converters.DateTimeConverterBase
{
public override object ReadJson(JsonReader reader, Type objectType,
object existingValue, JsonSerializer serializer)
{
throw new NotImplementedException();
}
public override void WriteJson(JsonWriter writer, object value,
JsonSerializer serializer)
{
writer.WriteValue(value.ToString());
}
}
admin.js中的初始化脚本
$(function () {
$(gridName).jqGrid({
// server url and other ajax stuff
url: '/Admin/Posts',
datatype: 'json',
mtype: 'GET',
height: 'auto',
// columns
colNames: colNames,
colModel: columns,
// pagination options
toppager: true,
pager: pagerName,
rowNum: 10,
rowList: [10, 20, 30],
// row number column
rownumbers: true,
rownumWidth: 40,
// default sorting
sortname: 'PostedOn',
sortorder: 'desc',
// display the no. of records message
viewrecords: true,
jsonReader: { repeatitems: false }
});
});
答案 0 :(得分:1)
您应该验证grid.locale-en.js
是否与jquery.jqGrid.src.js
存在于同一目录中。通常,所有语言文件都在子目录i18n
中。
以任何方式出现错误消息
无法获取未定义或空引用错误的属性“整数”
通常会在您加载jquery.jqGrid.src.js
(或jquery.jqGrid.min.js
)而不加载grid.locale-en.js
等语言特定文件时存在。
答案 1 :(得分:0)
我已经解决了这个问题。包含网格的JQueryUI选项卡无法正常工作,并且不会隐藏选项卡集中的其他div。一旦我使标签正常工作,jqGrid完美呈现