asp.net-mvc - 引导程序未按预期工作
问题描述
我正在使用 Bootstrap 和 jQuery Datatables 来设计前端,但是我的代码在浏览器中出现了一些混乱,我认为问题在于包含 bootstrap 或 jquery 或者版本可能是:-
我正在使用 ASP.NET MVC 5 空模板,我正在使用的文件是:-
索引.cshtml
@{
ViewBag.Title = "Employee List";
}
<h2>Employee CRUD Operation</h2>
<table id="employeeTable" class="table table-striped table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Salary</th>
</tr>
</thead>
</table>
<link href="https://cdn.datatables.net/1.10.16/css/dataTables.bootstrap.min.css" rel="stylesheet" />
@section scripts{
<script src="//cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.16/js/dataTables.bootstrap.min.js"></script>
<script>
$(document).ready(function () {
$("#employeeTable").DataTable({
"ajax": {
"url": "/Employee/GetData",
"type": "GET",
"datatype":"json"
},
"columns": [
{ "data": "Name" },
{ "data": "Position" },
{ "data": "Office" },
{ "data": "Age" },
{ "data": "Salary" }
]
});
});
</script>
}
bootstrap 和 jquery 包含在 _layout.cshtml 中:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My ASP.NET Application</title>
<link href="~/Content/Site.css" rel="stylesheet" type="text/css" />
<link href="~/Content/bootstrap.min.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>ASP.NET MVC Operations</p>
</footer>
</div>
<script src="~/Scripts/jquery-3.0.0.min.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
@RenderSection("scripts",required:false)
</body>
</html>
解决方案
我通过使数据表版本的引导程序与基本引导程序版本相同来解决了这个问题
推荐阅读
- python - 使用 Keras-tuner 进行超参数调整时的“准确性”错误
- reactjs - 如何修复引导表?
- java - 如何更改 eclipse 所以我不必手动导入
- amazon-web-services - 为什么控制塔帐户也需要 SSO 用户
- javascript - 数组未正确插入对象
- c - 如何获取elf二进制文件的堆起始地址
- javascript - 如何仅获取具有“用户”角色的用户?
- php - 在 wordpress 插件页面中执行表单的问题
- javascript - JavaScript 中的“.at()”有什么用?它在普通 JavaScript(浏览器 JavaScript)中是否有效?
- node.js - 如何使用 node.js 从 mongodb 数据库中获取随机数据