【发布时间】:2020-04-06 16:33:48
【问题描述】:
我有一个带有表格的页面,有一列,使用 DataTables;我使用 ajax 调用加载数据。
数据返回到页面但表格没有显示行。我在浏览器上没有任何错误显示。
这是我的带有 JQuery 的 HTML:
<div>
<table class="table table-bordered" id="DetailsTable" width="100%" cellspacing="0"</table>
</div>
<script>
jQuery(function () {
$('#DetailsTable').DataTable({
"responsive": true,
"processing": true,
"serverSide": true,
"ajax": {
"url": "/Index?handler=Table",
"type": "GET",
"dataSrc": "",
"dataType": "json"
},
"columnDefs": [
{ "targets": "detail_ID", visible: true }
],
"columns": [
{ "data": "detail_ID" }]
});
});
</script>
这是我的方法:
public async Task<IActionResult> OnGetTableAsync()
{
wItem = await _detailRepo.Finddetail(CancellationToken.None);
string NewtonJSON = JsonConvert.SerializeObject(wItem);
return Content(NewtonJSON);
}
这是重生的 JSON:
{
"detail_ID": 7,
"detail_GUID": "685b8741-fe22-460a-bb76-7ecd9c320172"
}
有什么建议吗?
【问题讨论】:
标签: c# ajax asp.net-core razor datatables