ajax - DataTables 警告:使用 Json 请求未知参数“FileName”...
问题描述
我有一个加载脚本的视图:
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 使用字符串正确格式化,但我无法弄清楚我缺少什么。我浏览了大约十几个其他有类似问题的帖子,但没有找到答案。
解决方案
请求第 0 行第 1 列的未知参数“文件名”。
在您的代码中,我们可以发现您使用 指定columns.data
了选项{ "data": "filename", "width": "20%" }
,如果数据源对象项的键fileName
如下所示(不是filename
您指定的),这将导致问题。
{"albumartpath":"https://xxxx/xxx","fileName":"xxx","title":"xxx","artist":"xxx","genre":"xx"}
因此,请仔细检查客户端收到的数据,并确保正确设置列的数据源。
推荐阅读
- amazon-web-services - NVidia 驱动程序停止在带有 Ubuntu 16.04 和 Tesla K80 GPU 的 AWS EC2 实例上工作
- python - Jython:NameError:未定义全局名称
- python - 正则表达式在几种情况下匹配版权声明中的公司名称
- python - 如何从文件中读取不同的度量值并保存?
- c# - c#.net 和 sqlserver 中的图像导航
- c++ - 在按键时更改 GLFWwindow 的背景
- algorithm - 3 嵌套for循环复杂度
- python - 如何使用 Python NetworkX 在有向图中找到最长的 10 条路径?
- server - open62541:发布温度值
- java - 后台获取速度