asp.net-mvc - 未使用 Asp.net MVC 加载数据表
问题描述
我正在为我的学习创建一个简单的 crud 系统。我是 Asp.net MVC 的初学者。我正在尝试从数据库中加载数据,但我可以完成任务。到目前为止我尝试过的内容附在下面。我创建了名称为技能的数据库,并且有一个表课程试图加载它 dataTable.while 运行程序时出现错误 错误
Uncaught TypeError: $(...).DataTable is not a function
at HTMLDocument.<anonymous> (Index:81)
at e (jquery-3.4.1.min.js:2)
at t (jquery-3.4.1.min.js:2)
控制器页面
public ActionResult Index()
{
return View();
}
public ActionResult GetSkill()
{
using (skillEntities sk = new skillEntities())
{
var course = sk.courses.OrderBy(a => a.id).ToList();
return Json(new { data = course }, JsonRequestBehavior.AllowGet);
}
}
查看页面
@{
ViewBag.Title = "Home Page";
}
<html>
<head>
<link href="~/Content/bootstrap.css" rel="stylesheet" />
<link href="~/Content/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" rel="stylesheet">
</head>
<body>
<div style="width:90%; margin:0 auto" class="tablecontainer">
<a class="popup btn btn-primary" href="/home/save/0" style="margin-bottom:20px; margin-top:20px;">Add New Employee</a>
<table id="myDatatable">
<thead>
<tr>
<th>ID</th>
<th>Course Name</th>
<th>Fee</th>
</tr>
</thead>
</table>
</div>
<script src="~/Scripts/jquery-3.4.1.js"></script>
<script src="~/Scripts/jquery-3.4.1.min.js"></script>
<script src="~/Scripts/jquery.validate.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery-ui-1.12.1.min.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function () {
var oTable = $('#myDatatable').DataTable({
"ajax": {
"url": '/home/GetSkill',
"type" : "get",
"datatype": "json"
},
"columns": [
{ "data": "id", "autoWidth": true },
{ "data" : "coursename", "autoWidth" : true},
{ "data": "fee", "autoWidth": true }
]
})
})
</script>
</body>
</html>
解决方案
你已经包含了 jquery 库两次,尝试删除下面的行,只使用 min.js
<script src="~/Scripts/jquery-3.4.1.js"></script>
推荐阅读
- r - 如何计算没有NA的总数
- java - 谁能告诉我为什么我的 IFile 总是返回 null?
- r - 使用 ggplot2 添加图例
- ios - 如何在 SwiftUI 中为按下时的导航链接设置动画?
- php - 使用 .htaccess 在 .html 页面上运行 php
- java - Android Studio Build 使用 NDK 失败
- flutter - 如何写入xml文件并保存?
- android - 如何在没有 android studio 但使用 Visual Studio 代码的情况下开发 android 应用程序
- git - 让我的 github master 分支匹配另一个分支
- r - 一列基于另一列的 R 平均值