【问题标题】:DataTables warning: Requested unknown parameter "FileName"... using JsonDataTables 警告:使用 Json 请求未知参数“FileName”...
【发布时间】: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


    【解决方案1】:

    为第 0 行第 1 列请求未知参数“文件名”。

    在您的代码中,如果数据源对象项的键为 fileName 如下所示(不是filename您指定),这将导致问题。

    {"albumartpath":"https://xxxx/xxx","fileName":"xxx","title":"xxx","artist":"xxx","genre":"xx"}
    

    所以请仔细检查客户端收到的数据,并确保正确设置列的数据源。

    【讨论】:

      猜你喜欢
      • 2018-02-26
      • 1970-01-01
      • 2014-01-16
      • 1970-01-01
      • 2016-09-02
      • 2013-05-08
      • 2019-11-13
      • 2016-09-24
      • 2021-06-08
      相关资源
      最近更新 更多