我在下面写了一段代码,用于从控制器加载JQ网格但Grid没有加载任何值
<script type="text/javascript">
$(this.document).ready(function () {
debugger;
$("#loadLogFile").jqGrid({
url: '/Home/Getresult',
datatype: 'json',
contentType: "application/json; charset-utf-8",
mType: 'GET',
colName: ['Log', 'Name'],
colModel: [
{ name: 'Log', index: 'Log', width: 20, stype: 'text' },
{ name: 'Name', index: 'Name', width: 20, stype: 'text' }
],
gridview: true,
loadonce: true,
viewrecords: true,
rowNum: 10,
rowList: [10, 20, 30],
viewrecords: true,
pager: '#pager',
height: 'auto',
width: '100%',
autowidth: true,
caption: "Log File Grid"
});
jQuery("#pager").jqGrid('navGrid', '#pager',
{ edit: false, add: false, del: false });
});
下面是C#代码
[HttpGet]
public JsonResult Getresult()
{
// string[] list = Directory.GetFiles(@"D:\logs");
Logfile log = new Logfile();
log.Log = "Test";
log.Name = "Test";
Logfile log1 = new Logfile();
log1.Log = "Test1";
log1.Name = "Test1";
List<Logfile> lLog = new List<Logfile>();
lLog.Add(log);
lLog.Add(log1);
var json = JsonConvert.SerializeObject(lLog);
return Json(json, JsonRequestBehavior.AllowGet);
}
不确定下面编码出错的地方是在布局页面中调用的JS和CSS文件
<link href="~/Content/ui.jqgrid.css" rel="stylesheet" />
<script src="~/Scripts/jquery-1.10.2.js"></script>
<link href="~/Scripts/jquery-ui.css" rel="stylesheet" />
<script src="~/Scripts/i18n/grid.locale-en.js"></script>
<script src="~/Scripts/jquery.jqGrid.js"></script>