C# 数据表不';表上的t效应
我在MVC中使用DataTable库,但它不起作用 这是视图部分C# 数据表不';表上的t效应,c#,model-view-controller,datatable,C#,Model View Controller,Datatable,我在MVC中使用DataTable库,但它不起作用 这是视图部分 <table id="example" class="display" style="width:100%"> <thead> <tr> <th>Id</th> <th>Phone</th> &
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>Id</th>
<th>Phone</th>
<th>FirstName</th>
<th>LastName</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<th>Id</th>
<th>Phone</th>
<th>FirstName</th>
<th>LastName</th>
</tr>
</tfoot>
</table>
<script type="text/javascript">
//$(document).ready(function () {
// $('#example').DataTable();
//})
$(document).ready(function () {
GetEmployeeRecord();
})
var GetEmployeeRecord = function () {
$.ajax({
type: "Get",
url: "/BasicInfo/GetCustomers",
success: function (response) {
alert("success");
BindDataTable(response);
},
error: function () {
alert("error");
}
})
}
var BindDataTable = function (response) {
$("#example").DataTable({
"aaData": response,
"aoColumns": [
{ "mData": "Id" },
{ "mData": "Phone" },
{ "mData": "FirstName" },
{ "mData": "lastName" }
]
});
}
身份证件
电话
名字
姓氏
身份证件
电话
名字
姓氏
//$(文档).ready(函数(){
//$(“#示例”).DataTable();
//})
$(文档).ready(函数(){
GetEmployeeRecord();
})
var GetEmployeeRecord=函数(){
$.ajax({
键入:“获取”,
url:“/BasicInfo/GetCustomers”,
成功:功能(响应){
警惕(“成功”);
BindDataTable(响应);
},
错误:函数(){
警报(“错误”);
}
})
}
var BindDataTable=函数(响应){
$(“#示例”).DataTable({
“aaData”:回应,
“aoColumns”:[
{“mData”:“Id”},
{“mData”:“Phone”},
{“mData”:“FirstName”},
{“mData”:“lastName”}
]
});
}
这是控制器部分
public JsonResult GetCustomers()
{
SalonEntities db = new SalonEntities();
List<Customer> CustomerList = db.Customers.OrderByDescending(a => a.ID).ToList();
return Json(CustomerList , JsonRequestBehavior.AllowGet);
}
publicjsonresult GetCustomers()
{
SalonEntities db=新的SalonEntities();
List CustomerList=db.Customers.OrderByDescending(a=>a.ID.ToList();
返回Json(CustomerList,JsonRequestBehavior.AllowGet);
}
虽然控制器中的CustomerList已加载,但它返回到视图,并进入jquery的错误部分
可能是什么问题?对控制器的ajax调用失败。要对此进行调试,您可以做两件事: 提醒错误 删除(dobule引号)
“
,以警告实际错误
error: function () {
alert(error);
}
您很可能能够在控制台的开发人员工具中看到它
检查网络选项卡
在“网络”选项卡中,您将看到错误(4XX、5XX)或类似错误,并提供一些额外信息(如果幸运的话)
如果没有更多信息,并且出现错误500,则需要检查后端代码中的异常情况。为什么是“aaData”和“aoColumns”?文档说应该是,并且有错误500,但后端代码会完美地返回列表检查服务器端的事件查看器以查看错误。