I have the following javascript snippet:
$.ajax({ url: self.LoadCirculationListUrl, cache: false, async: false, dataType: 'json', contentType: 'application/json; charset=utf-8', data: [ { "ColumnName":"France","Comparitor":"=","Value":"1"},{"ColumnName":"Germany","Comparitor":">","Value":"3"}] });
Here is the control accessed by the above ajax call:
public ActionResult LoadCirculationData(IList<CirculationListFilter> filters) { }
Here is the CirculationListFilter class
public sealed class CirculationListFilter { public string ColumnName { get; set; } public string Comparitor { get; set; } public string Value { get; set; } }
Now, when I run the code, the controller does not receive the JSON collection passed to it; filters always zero. However, if I do this:
$.ajax({ url: self.LoadCirculationListUrl, cache: false, async: false, dataType: 'json', contentType: 'application/json; charset=utf-8', data: { "ColumnName":"Germany","Comparitor":">","Value":"3"} });
and the contoller is as follows:
public ActionResult LoadCirculationData(CirculationListFilter filters) { }
Data is transmitted in order. Why can't the controller bind a collection of JSON elements?
EDIT:
I modified the AJAX call to use this:
data: { filters: [{ "ColumnName": "France", "Comparitor": "=", "Value": "1" }, { "ColumnName": "Germany", "Comparitor": ">", "Value": "3" }]},
and ActionResult:
public ActionResult LoadCirculationData(List<CirculationListFilter> filters)
filters now contain 2 elements inside, but each of the CirculationListFilter classes is populated with NULL data in its properties. So I'm getting closer, but the actual values ββare not tied.