gpt4 book ai didi

jquery数据表服务器端处理.net Core

转载 作者:行者123 更新时间:2023-12-01 05:13:45 25 4
gpt4 key购买 nike

我正在使用 jquery datatable 和 .net core 来构建网格我正在使用服务器端处理我正在使用这个包GitHub Link

我遇到的问题是请求第 0 行第 0 列的未知参数“CivilID”

客户端

var table = $('#tblClient').DataTable({
language: {
processing: "Loading Data...",
zeroRecords: "No matching records found"
},
processing: true,
serverSide: true,
orderCellsTop: true,
autoWidth: true,
deferRender: true,
dom: '<tr>',
ajax: {
type: "POST",
url: '/Client/LoadTable/',
contentType: "application/json; charset=utf-8",
async: true,

data: function(data) {
let additionalValues = [];
additionalValues[0] = "Additional Parameters 1";
additionalValues[1] = "Additional Parameters 2";
data.AdditionalValues = additionalValues;
return JSON.stringify(data);
}
},

columns: [
{
title: "CivilID",
data: "CivilID",
},
{
title: "LastName",
data: "LastName"
}, {
title: "FirstName",
data: "FirstName"
}
]
});

服务器端

public async Task<IActionResult> LoadTable([FromBody]DTParameters param) {
try {
// var data = await _demoService.GetDataAsync(param);
List<ClientViewModel> ClientsList = new List<ClientViewModel>();

var result = HttpContext.Session.GetString("AllClients");
ClientsList = JsonConvert.DeserializeObject<List<ClientViewModel>>(result);

var json= new JsonResult(new DTResult<ClientViewModel> {
draw = param.Draw,
data = ClientsList,
recordsFiltered = ClientsList.Count,
recordsTotal = ClientsList.Count
});
return json;
} catch (Exception e) {

}
}

数据 enter image description here

图中的数据是针对ClientViewModel的它在客户端具有相同的名称我缺少什么谢谢

最佳答案

将此添加到startup.cs

services.AddMvc()
.AddJsonOptions(options =>
{
options.SerializerSettings.ContractResolver
= new Newtonsoft.Json.Serialization.DefaultContractResolver();
});

关于jquery数据表服务器端处理.net Core,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55286638/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com