【发布时间】:2019-01-23 18:30:23
【问题描述】:
我有一个在 $( document ).ready 函数中创建的表格。我也在使用 jQuery DataTables 插件。出于某种原因,当页面加载时,表格会加载,但第一行显示:
“表中没有可用数据”。
我的控制器:
public string Lowx()
{
var query = db.Infos.
Include(x => x.Profile).
Include(x => x.Cars).
ToList();
return JsonConvert.SerializeObject(query.ToList());
}
我的观点:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<link href="~/Content/DataTables/css/jquery.dataTables.min.css" rel="stylesheet" />
<link href="~/Content/bootstrap.min.css" rel="stylesheet" />
<link href="~/Content/Site.css" rel="stylesheet" />
<title>Service</title>
</head>
<body>
<p>
<h1 align="center"> Сервис по обслуживанию автомобилей</h1>
<ul id="nav">
</ul>
<a href='@Url.Action("Create")'><img src='/Content/addlow.png' width="40" height="40" /></a>
</p>
<table class="table" id="cars">
<thead>
<tr>
<th>Имя</th> //firstname
<th>Фамилия</th> //lastname
<th>Отчество</th> //middlename
<th>День рождения</th> //birthday
<th>Марка машины</th> //carname
<th>гос.номер</th> //carnumber
</tr>
</thead>
</table>
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
<script src="~/Scripts/DataTables/jquery.dataTables.min.js"></script>
<script type="text/javascript">
$(document).ready(function (data) {
// Here is my datatable configuration
$('#cars').DataTable({
ajax: {
url: '@Url.Action("lowx")',
type: 'POST',
dataType: 'json',
dataSrc: ""
},
columns: [
{ data: "FirstName", name: "FirstName" },
{ data: "LastName", name: "LastName" },
{ data: "MiddleName", name: "MiddleName" },
{ data: "BirthDate", name: "BirthDate" },
{ data: "CarName", name: "CarName" },
{ data: "CarNumber", name: "CarNumber" },
],
});
});
</script>
</body>
</html>
无法弄清楚问题究竟出在哪里。任何帮助将不胜感激。
谢谢。
【问题讨论】:
标签: c# jquery json asp.net-mvc datatables