我正在構建一個具有 N 層架構的 Asp.net Core 專案。我正在使用 DataTable,我想用 Ajax 加載資料,但我忽略了一些事情。這是我的代碼;
我的觀點;
<script type ="text/javascript">
$(document).ready(function (){
$('#myTable').DataTable({
ajax: {
url: "/api/Values",
dataSrc: ""
},
columns: [
{ data: "Id" },
{ data: "Name" },
{ data: "Description" },
{ data: "Date" },
{ data: "Deleted" },
{
data: "id",
render: function (data, type, row,meta) {
return "<button class='btn btn-primary' style='margin-right:5px;' onclick=Edit(" JSON.stringify(row) ")>Edit</button>"
"<button class='btn btn-danger' onclick=Delete(" JSON.stringify(row) ")>Delete</button>";
}
},
]
});
});
</script>
我的 API 控制器代碼;
namespace MottoUI.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
RoleManager rm = new RoleManager(new EfRoleRepository());
IRoleService _roleService = null;
public ValuesController(IRoleService roleService)
{
_roleService = roleService;
}
// GET: api/<ValuesController>
[HttpGet]
public IEnumerable<Role> GetRole()
{
return _roleService.GetList();
}
}
我的物體結構;
public class Role
{
public Guid Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public DateTime Date { get; set; }
public bool Deleted { get; set; }
}
我收到了這個錯誤;

轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/461400.html
標籤:jQuery 网 阿贾克斯 asp.net-mvc asp.net 核心
