在我开始融合设计师的造型之前,这对我有用。仅供参考,数据表通过NuGet与JQuery和JQueryUI一起安装。我在Chrome的开发工具中不断收到以下错误:
Uncaught TypeError: $(...).DataTable is not a function
这是我的代码--- 在我的_Layout.cshtml中:
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")
@RenderBody()
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
然后在页面视图中:
<link href="~/Content/DataTables/css/jquery.dataTables.css" rel="stylesheet" />
<script src="~/Scripts/DataTables/jquery.dataTables.min.js"></script>
<table id="ArticlesTable" class="display">
<thead>
<tr>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.Articles)
{
var pubDate = item.DatePublished;
var pubDateShort = pubDate.ToShortDateString();
var pubDateDayOfWeek = pubDate.DayOfWeek.ToString();
<tr class="researchArticleContainerTR">
<td>
<div class="researchArticleContainerDIV">
<div class="researchArticleLeft">image placeholder</div>
<div class="researchArticleRight">
<div class="researchArticleTitle">
@Html.DisplayFor(modelItem => item.Title)
</div>
<div class="researchArticleCredits">
By @Html.DisplayFor(modelItem => item.Owner.FullName) on @(pubDateDayOfWeek) @(pubDateShort).
</div>
<div>
<p class="researchArticleShortDescription">
@Html.DisplayFor(modelItem => item.ShortDescription)
</p>
</div>
<br />
<a href="@(Url.Action("Research-Article-Details", new {id = ContentSpecific.SlugifyResearchArticleLinkText(item)}))">Read our full report ></a>
</div>
</div>
</td>
</tr>
<tr class="researchArticleTRSpacer"></tr>
}
</tbody>
</table>
<script type="text/javascript">
$(document).ready(function () {
// archive list ddl
$("#ArchiveList").change(function () {
location.href = '@Url.Action("Archive", "ResearchArticle", new { id = "" })/' + $(this).val(); // get val from ddl
});
// setup results as datatable
$('#ArticlesTable').DataTable(); <-- bombing here ===!!
});
JQuery被加载了,但不是DataTables ......现在,事情已经在我身上移动了许多将设计合并到逻辑中...也许事情变得混乱了。任何想法?
答案 0 :(得分:0)
我很糟糕......还有其他一些JS在运行;数据表;这是我们的设计师使用的adobe awesome-font的东西。我把它移到了DataTables的参考文献下面并再次繁荣起来。