I am trying to submit a json to an API method that takes a model with some IEnumerables, but the IEnumerable members are always coming through as null. At this point the controller doesn't do anything, I'm just using a breakpoint to see if the data is coming though.
My json:
{
"apiModel": {
"Results":[
{
"ActivityIdentifier":"abc",
"CharacteristicName": "Dissolved Oxygen",
"SubmitData": true
},
{
"ActivityIdentifier":"efg",
"CharacteristicName": "pH",
"SubmitData": true
}
]
}
}
My api controller:
[HttpPost]
public void Post([FromBody]APIIncomingViewModel apiModel)
{
IEnumerable<IncomingResult> results = apiModel.Results;
// IEnumerable<Activity> activity = apiModel.Activities;
}
My model:
namespace MyNameSpace.Models
{
public class APIIncomingViewModel
{
//public IEnumerable<Activity> Activities { get; set; }
public IEnumerable<IncomingResult> Results { get; set; }
}
}
Results model:
namespace MyNameSpace.Models
{
public class IncomingResult
{
public string ActivityIdentifier { get; set; }
public string CharacteristicName { get; set; }
public bool SubmitData { get; set; }
}
}
I'm getting an apiModel object, but the Results member is null. I would eventually like to have other IEnumerables in there like Activities.
I have tried making Results an IncomingResult[], and I've tried a lot of different forms for the json, but nothing seems to change - Results is always null.
In this thread I saw it mentioned that you might have to put it inside an anonymous object, but I'm not sure how to handle it if I'm ultimately posting both Results and Activities, and I don't plan on using jQuery's ajax in any case - this will be coming from a mobile app. Right now I'm just posting the json using Postman. I'm also not sure why it didn't work for me as an array.
Any help in figuring out the correct format would be much appreciated.