【发布时间】:2011-10-26 11:12:07
【问题描述】:
我的 jqGrid 有问题。我在这里看到过其他类似问题的帖子,除了我的特别之处在于数据在我的开发机器中正确加载但是当我在生产服务器上发布站点时,jqGrid 不会加载数据,我得到的只是一个空的网格。除了 jqGrid 之外,服务器中对数据的所有其他 ajax 请求都可以正常工作。我的项目在 MVC3 中,我在 win2008 IIS7 中托管该站点。这是我当前的代码:
查看:
<script type="text/javascript">
$(document).ready(function () {
$("#grid").jqGrid({
url: '@Url.Action("LoadAction", "Controller", new { area = "Area" })',
editurl: '@Url.Action("SaveAction", "Controller", new { area = "Area" })',
datatype: 'json',
mtype: 'POST',
colNames: [
'@Html.LabelFor(v => new foo.bar.MyClass().Property1)',
'@Html.LabelFor(v => new foo.bar.MyClass().Property2)',
'@Html.LabelFor(v => new foo.bar.MyClass().Property3)',
'@Html.LabelFor(v => new foo.bar.MyClass().Property4)'
],
colModel: [
{ name: 'Property1', index: 'Property1', editable: true },
{ name: 'Property2', index: 'Property2', editable: true, edittype: "select", editoptions: { value: "Option1:Option1;Option2:Option2"} },
{ name: 'Property3', index: 'Property3', editable: true },
{ name: 'Property4', index: 'Property4', editable: true }
],
pager: $('#gridPager'),
rowNum: 20,
rowList: [10, 20, 50, 100],
sortname: 'Property1',
sortorder: "asc",
viewrecords: true,
imgpath: '',
shrinkToFit: true,
width: 940,
height: 300,
gridview: true
});
});
</script>
<div>
<table id="grid" class="scroll" cellpadding="0" cellspacing="0"></table>
<div id="gridPager" class="scroll" style="text-align:center;"></div>
</div>
控制器:
[Authorize]
public JsonResult LoadAction(string sidx, string sord, int page, int rows)
{
List<foo.bar.MyClass> list = foo.bar.MyClassController.getAll();
int pageIndex = Convert.ToInt32(page) - 1;
int pageSize = rows;
int totalRecords = list.Count();
int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
var jsonData = new
{
total = totalPages,
page,
records = totalRecords,
rows = (
from myclass in list
select new
{
id = myclass.Id,
cell = new string[] {
myclass.Property1,
myclass.Property2,
myclass.Property3,
myclass.Property4
}
}).ToArray()
};
return Json(jsonData);
}
有人知道可能是什么问题吗?
谢谢。
【问题讨论】:
标签: json asp.net-mvc-3 jqgrid