我的网络应用有问题。当我运行它时,我得到Ajax错误。我检查了它是否是数据库问题,但应用程序在getdata()方法中成功获取数据。问题出现在此脚本的某处。
这是datatable的定义:
<table id="tableID" class="table table-striped table-bordered" style="width:100%">
<thead>
<tr>
<th>Party name</th>
<th>Description</th>
<th>Start date and time</th>
<th>Picture</th>
</tr>
</thead>
</table>
这是应填充数据表的脚本:
$(document).ready(function () {
$('#tableID').dataTable({
"serverSide": true,
"ajax": {
"url": "/party/getdata",
"type": "GET",
"datatype": "json"
},
"columns": [
{ "data": "name", "autoWidth": true },
{ "data": "description", "autoWidth": true },
{ "data": "startDayTimeParty", "autoWidth": true },
{ "data": "image", "autoWidth": true }
]
});
});
这是getdata()
方法:
[HttpGet]
public ActionResult getdata() {
using (DBModels db = new DBModels()) {
var partyList = db.party.OrderBy(a => a.name).ToList();
return Json(new { data = partyList}, JsonRequestBehavior.AllowGet);
}
}
party.cs类(数据库模型类):
public partial class party
{
public party()
{
this.clubID = 1;
}
public int partyID { get; set; }
public string name { get; set; }
public string description { get; set; }
public System.DateTime startDayTimeParty { get; set; }
public int goingNumberGuests { get; set; }
public int clubID { get; set; }
public byte[] image { get; set; }
public virtual club club { get; set; }
}