我是 MVC、jquery 和 DataTables 的菜鸟。当我按 F5 构建并在本地启动站点以进行开发/调试时,我收到一个 Microsoft Visual Studio 警告对话框:
JavaScript runtime error: Object doesn't support property or method 'dataTable'
我正在将 VS 2012 与 MVC 4 项目一起使用。我使用 NuGet 包管理器作为我的解决方案来安装\更新 jQuery 1.8.3 和 jquery.datatables 1.9.4。这是我的 Index.cshtml View 代码:
<script src="@Url.Content("~/Scripts/jquery-1.8.3.js")" type="text/javascript"> </script>
<script src="@Url.Content("~/Scripts/DataTables-1.9.4/media/js/jquery.dataTables.js")" type="text/javascript"></script>
<script>
$(document).ready(function () {
$('#table_id').dataTable({
});
});
</script>
<table id="table_id" class="display">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
</tbody>
</table>
这似乎是一个引用问题,但我尝试过的任何方法都无法解决该问题!
我已经搜索过博客,但找不到答案,或者也许无法理解需要更改的内容。直接回答将不胜感激!
谢谢!
最佳答案
我认为您可以尝试注释掉这些行:
@Scripts.Render("~/bundles/jquery")
@RenderSection(“脚本”,必需:false)
位于“_Layout.cshtml”页面的末尾。
希望这是有道理的
关于jquery - MVC 4 Razor 对象不支持属性或方法 'dataTable',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14322413/