【发布时间】:2020-06-22 00:32:52
【问题描述】:
我有一个加载脚本的视图:
var dataTable;
$(document).ready(function () {
loadDataTable();
});
function loadDataTable() {
dataTable = $('#DT_load').DataTable({
"ajax": {
"url": "/musicfiles/getall/",
"type": "GET",
"datatype": "json"
},
"columns": [
{
"data": "albumartpath",
"render": function (data) {
return `<img src="~/images/" + ${data} ?? "noimage.webp" asp-append-version="true" height="50" width="50" />`;
}, "width": "20%"
},
{ "data": "filename", "width": "20%" },
{ "data": "title", "width": "20%" },
{ "data": "artist", "width": "20%" },
{ "data": "genre", "width": "20" }
],
"language": {
"emptyTable": "no data found"
},
"width": "100%"
});
}
还有一个返回 Json 的 MusicFilesController 函数:
[HttpGet]
public async Task<IActionResult> GetAll()
{
JsonResult json = Json(new { data = await _context.MusicFiles.ToListAsync() });
return json;
}
但是当我加载页面时,我得到了错误:
DataTables 警告:表 id=DT_load - 请求第 0 行第 1 列的未知参数“文件名”。有关此错误的详细信息,请参阅http://datatables.net/tn/4
Json 使用字符串正确格式化,但我无法弄清楚我缺少什么。我浏览了大约十几个其他有类似问题的帖子,但没有找到答案。
【问题讨论】:
标签: ajax asp.net-core datatables asp.net-core-mvc