我在mvc中使用jquery数据表。我已正确加载脚本文件,但仍然无法使用数据。
_layout.cshtml中的代码:
<!--Data table jquery-->
<script src="~/Content/jquery-2.2.3.js"></script>
<script src="~/Content/datatables/jquery.dataTables.js"></script>
以及 index.cshtml 中的数据表代码:
$(document).ready(function () {
//jQuery DataTables initialization
var table = $('#MyTable').DataTable({
"processing": true, // for show processing bar
"serverSide": true, // for process on server side
"orderMulti": false, // for disable multi column order
"dom": '<"top"ip>rt<"bottom"lp><"clear">', // for hide default global search box // little confusion? don't worry I explained in the tutorial website
"ajax": {
"url": "/Product/LoadData",
"type": "POST",
"datatype": "json"
},
"aoColumns": [
{ "mData": "ProductID", "name": "ProductID", "visible": false, "autoWidth": true },
{ "mData": "ProductName", "name": "ProductName", "visible": false, "autoWidth": true },
{ "mData": "Qty", "name": "Qty", "autoWidth": true },
{ "mData": "UnitPrice", "name": "UnitPrice", "visible": true, "autoWidth": true },
{ "mData": "CatagoryID", "name": "CatagoryID", "autoWidth": false },
{ "mData": "catagoryname", "name": "catagoryname", "visible": true, "autoWidth": true }
]
});//End DataTable
});
当我运行它时会出现以下错误:
未捕获TypeError:$(...)。DataTable不是函数 (匿名函数)@产品:91 fire @ jquery-2.2.3.js:3187 fireWith @ jquery-2.2.3.js:3317 ready @ jquery-2.2.3.js:3536 完成@ jquery-2.2.3.js:3552
答案 0 :(得分:0)
你的_layout中有你的datatable.js,你可能会产生冲突,最后设置你的datatable.js基准索引以及运行$()时预先加载所有DOM的数据表声明。