Trying to pass a list of objects to my MVC controller from my jquery script. The controller ain't getting the list. Any ideas?
Script
function refreshXeroData(obj, planId, date, list) {
// list comes in as a serialized array
// list = "[{"Id":245225,"XeroFromDate":"4/22/2015 12:00:00 AM","XeroToDate":""},{"Id":245226,"XeroFromDate":"4/1/2016 12:00:00 AM","XeroToDate":"4/30/2016 12:00:00 AM"}]"
var model = { PlanId: planId, Date: date, List: list };
$.ajax({
type: 'POST',
url: url,
data: model,
success: function (data) {
// code removed for clarity
},
});
}
Controller
public JsonResult Refresh(int planId, DateTime date, List<XeroScenarioModel> list)
{
// list is null
// code removed for clarity
}
Model
public class XeroScenarioModel
{
public int Id { get; set; }
public string XeroFromDate { get; set; }
public string XeroToDate { get; set; }
}
stringnot aList. Tryjson_decodeon the list string before adding it to the model.contentType: "application/json; charset=utf-8",and change it todata: JSON.stringify(model)