【发布时间】:2016-01-29 19:23:14
【问题描述】:
我目前正在玩 MVC6 的第一个乐趣,但我在使用 Datatables 时遇到了一些问题。据我所知,我已经包含了应该存在的所有内容,但是每次我尝试运行代码时都会收到一个错误,提示 jquery.datatables.min 看不到 Jquery。
代码如下:
<link href="//cdn.datatables.net/1.10.10/css/jquery.dataTables.min.css" rel="stylesheet" />
<script type="text/javascript" charset="utf-8" src="//cdn.datatables.net/1.10.10/js/jquery.dataTables.min.js"></script>
<script src="http://code.jquery.com/jquery-2.2.0.min.js"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready( function () {
$('#datatable2').DataTable();
} );
</script>
<table class="table table-striped table-hover" id="datatable2" cellspacing="0">
<tr>
<th>ID</th>
<th>Problem Description</th>
<th>Solution</th>
</tr>
@foreach(var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.ProblemID)
</td>
<td>
@Html.DisplayFor(modelItem => item.ProblemDescription)
</td>
<td>
@Html.DisplayFor(modelItem => item.Solution)
</td>
</tr>
}
有什么想法吗?这可能是非常明显的事情......
*而且我知道脚本通常应该在 _layout 中,这只是一个测试项目,以感受 MVC 5 和 6 之间的变化。
【问题讨论】:
-
尝试以下操作:将 jquery 作为您的第一个脚本,然后是数据表脚本。将
<body></body>添加到您的表中。查看文档:datatables.net/manual/installation -
两个优点 - 也是我应该想到的......现在我们得到:0x800a01b6 - JavaScript 运行时错误:对象不支持属性或方法'DataTable'
-
你在
jquery.min.js之前已经包含了datatable.js呃……:D 首先解决这个问题。 -
另一件值得一提的事情是将你的脚本放在
@section scripts { }
标签: jquery asp.net-mvc datatables