我在我的应用程序中使用 Datatables,但没有触发获取数据控制器方法。我能够在 UI 上呈现表格,但即将到来的数据为 NULL。
这是我的代码
SITE.MASTER 中的导入项目
<link href="/Scripts/DataTables/media/css/demo_page.css" type="text/css" rel="stylesheet" />
<link href="/Scripts/DataTables/media/css/demo_table.css" type="text/css" rel="stylesheet" />
<script src="/Scripts/Lib/jquery-1.4.2.js" type="text/javascript" language="javascript"></script>
<script type="text/javascript" charset="utf-8" src="/Scripts/DataTables/media/js/jquery.dataTables.js"></script>
这是我的 HTML 外观
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>http://stackoverflow.com/questions/6946559/jqgrid-please-help</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" charset="utf-8">
$(document).ready(function () {
$('#example').dataTable({
bProcessing: true,
sAjaxSource: '@Url.Action("GridData", "Home")'
});
});
</script>
</head>
<div id="dynamic">
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
<thead>
<tr>
<th width="20%">Rendering engine</th>
<th width="25%">Browser</th>
<th width="25%">Platform(s)</th>
<th width="15%">Engine version</th>
<th width="15%">CSS grade</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</html>
这是我加载 HTML 的 JS 文件的外观
var rptTabs = function () {
return {
Init: function () {
var placeholder = $("#rpt-tab");
placeholder.setTemplateURL("/Templates/Home/report.htm");
placeholder.load("/Templates/Home/report.htm");
}
}
} ();
这是我的 Home 控制器方法的外观
public ActionResult GridData()
{
return Json(new
{
aaData = new[]
{
new [] { "Trident", "Internet Explorer 4.0", "Win 95+", "4", "X" },
new [] { "Gecko", "Firefox 1.5", "Win 98+ / OSX.2+", "1.8", "A" },
new [] { "Webkit", "iPod Touch / iPhone", "iPod", "420.1", "A" }
}
}, JsonRequestBehavior.AllowGet);
}
请告诉我我的实施有什么问题。