我正在尝试在我的 asp.net mvc4 应用程序中实现 jquerygrid 插件。但我卡住了。需要你的帮助。编写了所有代码,我只得到了带有 json 数据的白页。我不知道为什么。
我的观点如下图所示:
@model Fancy.Management.Model.User.IndexModel
@{
ViewBag.Title = "Index";
}
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#list").jqGrid({
url:'@Html.Action("Index","User")',
datatype: 'json',
mtype: 'GET',
colNames:['Id','Votes','Title'],
colModel :[
{name:'Id', index:'Id', width:40, align:'left' },
{name:'Votes', index:'Votes', width:40, align:'left' },
{name:'Title', index:'Title', width:200, align:'left'}],
pager: jQuery('#pager'),
rowNum:10,
rowList:[5,10,20,50],
sortname: 'Id',
sortorder: "desc",
viewrecords: true,
imgpath: '/scripts/themes/coffee/images',
caption: 'My first grid'
});
});
</script>
<table id="list" class="scroll" cellpadding="0" cellspacing="0"></table>
<div id="pager" class="scroll" style="text-align:center;"></div>
我的操作方法如下所示:
public ActionResult Index(string sidx, string sord, int? page, int? rows)
{
var jsonData = new
{
total = 1,
page = 1,
records = 3,
rows = new[]{
new{Id=1,cell=new[] {"1","-7","Is this good question?"}},
new{Id=2,cell=new[] {"2","15","Is this really?"}},
new{Id=3,cell=new[] {"3","23","Why is the sky blue?"}}
}
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
我得到的异常如下所示: