我正在用.NET开发DataTables应用程序。尝试运行我的应用程序时,出现以下错误消息:
DataTables警告:表id = tbl_NameValue-请求的第0行第0列的未知参数“名称”。有关此错误的更多信息,请参见http://datatables.net/tn/4
我的HTML:
<div class="row container">
<table id="tbl_NameValue" class="display" style="direction:rtl;">
<thead>
<tr>
<th>Name</th>
<th>Value </th>
<th>GroupName </th>
</tr>
</thead>
</table>
</div>
我的JavaScript:
$(document).ready(function () {
$('#tbl_NameValue').DataTable({
"ajax": {
"url": "/BaseInfo/NameValueSelectAll",
"type": "GET",
"datatype": "json"
},
"columns":
[{
data: 'Name'
}, {
data: 'Value'
}, {
data: 'GroupName'
}
],
"language": {
"url": "//cdn.datatables.net/plug-ins/1.10.19/i18n/Persian.json"
}
});
});
我的C#:
public IActionResult NameValueSelectAll() {
List < NameValueModel > result;
using(NameValueDA dataAccess = new NameValueDA()) {
var dt = dataAccess.SelectAll();
result = this.NameValueGetList(dt);
}
string tmp = JsonConvert.SerializeObject(result);
return Json(new {
data = tmp
});
}
public List < NameValueModel > NameValueGetList(DataTable datatable) {
List < NameValueModel > result = new List < NameValueModel > ();
result = (from DataRow dr in datatable.Rows
select new NameValueModel() {
Name = Convert.ToString(dr["NMVL_Name"]),
Value = Convert.ToInt32(dr["NMVL_Value"]),
GroupName = Convert.ToString(dr["NMVL_GroupName"])
}).ToList();
return result;
}