There are a lot of question like this, but I cannot find what I'm doing wrong in my specific case. I am trying to build a JSON collection of objects and bind it to my controller action's parameter.
At the moment, I am only trying to bind Name property to the list. The only issue I can think of might be my JSON collection structure.
AJAX:
function GetFilteredDatatablesValues() {
var data = {
Columns: []
};
for (var i = 0; i < 5; i++) {
var column = {
Name: "name" + i
};
data.Columns.push(column);
}
data = JSON.stringify(data);
$.ajax({
url: '/Client/DatatablesSearchTest',
type: 'POST',
contentType: "application/json; charset=utf-8",
dataType: 'json',
data: data,
error: function (response) {
},
success: function (data) {
}
});
}
Controller action:
public JsonResult DatatablesSearchTest(List<DataTableColumn> Columns) //Columns contains 0 items
{
List<DataTableColumn> test = Columns;
return Json(new { success = true });
}
Model:
public class DataTableColumn
{
public int Data { get; set; }
public string Name { get; set; }
public bool Orderable { get; set; }
public bool Searchable { get; set; }
public Search Search { get; set; }
public DataTableColumn()
{
Search = new Search();
}
}