I have a ASP.NET API that expects a string model:
[HttpPost]
public ActionResult Add(string model)
{
var m = JsonConvert.DeserializeObject<CustomModel>(model);
...
}
So far, I have been doing this to pass data to it:
var addModel = {
"SomeValue": {
"Some": "example",
"Value": "example"
},
"AnotherValue": "example"
}
var model = JSON.stringify(addModel);
And it works just fine. But now I need to ship data this way:
var addModel = {
"SomeValue": {
"Some": "example",
"Value": "example"
},
"AnotherValue": "example",
"MyArray[0].SomeValue": 1,
"MyArray[0].AnotherValue": a,
"MyArray[1].SomeValue": 1,
"MyArray[1].AnotherValue": a,
}
How do I add MyArray to the object so it can be passed to the back-end in the proper format?
{ "key": []}this is the way to add an array into an objectaddModel.MyArray.push( { "SomeValue" : 1, "AnotherValue": a })afteraddModelis declared