【发布时间】:2012-12-30 10:29:21
【问题描述】:
我在我的应用程序中使用 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);
}
请告诉我我的实现有什么问题。
【问题讨论】:
-
这个
rptTabs变量是什么?它与您的问题有什么关系? -
rpttabs 是一个选项卡,我将在其中呈现数据。这个第一个控件会来,然后它会加载 HTML 模板。从那里数据表脚本触发器
-
我不确定我是否理解。你能显示正在使用它的代码吗?
-
HI Darin 问题已解决。我刚刚更改了 sAjaxSource 的语法,例如“sAjaxSource”:'/Home/GridData',它开始工作了..非常感谢您的支持..
-
哦,您使用的是 WebForms 视图引擎而不是 Razor?
标签: c# jquery asp.net-mvc datagrid grid