Make sure that the column names are the same. They are case sensitive. Here, in my case, i got this error when the column names of my model are in capitalzed and i used all the lower case letters in the data of ajax request.
So,i resolved by matching the column names exactly the same way as the existing model names.
DataTable Binding
$("#Customers").DataTable({
ajax: {
url: "/api/customers/",
dataSrc: ""
},
columns: [
{
data: "Name",
render: function (data, type, customer) {
return "<a href='/customers/edit/" + customer.Id + "'>" + customer.Name + "</a>";
}
},
{
data: "Name"
},
{
data: "Id",
render: function (data) {
return "<button class='btn-link js-delete' data-customer-id=" + data + ">Delete</button>";
}
}
]
});
Web API Method:
public IEnumerable<Customer> GetCustomers()
{
return _context.Customers.ToList();
}
My Model:-
public class Customer
{
public int Id { get; set; }
[Required]
[StringLength(255)]
public string Name { get; set; }
[Display(Name="Date Of Birth")]
public DateTime? BirthDate { get; set; }
public bool isSubscribedToNewsLetter { get; set; }
public MembershipType MembershipType { get; set; }
[Display(Name="Membership Type")]
[Required]
public byte MembershipTypeId { get; set; }
}
so here in my case, iam populating datatable with columns(Name,Name,Id).. iam duplicating the second column name to test.