Some objects in JSON are not binding to Model.
JS
var filterSet = {
"Filters":[Object1],
"FilterSets":[{
"Filters":[Object2,Object3],
"FilterSets":[{
"Filters":[Object4,Object5],
"FilterSets":[]
}]
}]
}
$.ajax({
url: '/ControllerName/GetData',
dataType: 'json',
data: JSON.stringify({
filterSet: filterSet
}),
type: 'POST',
contentType: 'application/json; charset=utf-8'
}).done(function (result) {
...
});
Controller
public JsonResult GetData(FilterSet filterSet)
{
....
return Json(data);
}
Model
public class Filter
{
public string Field1 { get; set; }
public string Field2 { get; set; }
...
public Filter()
{
...
}
}
public class FilterSet
{
public List<Filter> Filters { get; set; }
public List<FilterSet> FilterSets { get; set; }
public FilterSet()
{
Filters = new List<Filter>();
FilterSets = new List<FilterSet>();
}
}
The Filters list with Object4 and Object5 is bound, but the Filters list with Object1 and the Filters list with Object2 and Object3 are not. Or perhaps they are but are not getting populated with the correct values.
So all Filters siblings of non-empty FilterSets are just empty lists.
It doesn't seem to be the JS object causing this weird issue. I think it's something with the Model. What's missing from the Model? Or what's wrong in general?