I am POSTing to the server (.Net) and I am having trouble passing arrays to the controller action. I've tried just about every possible combination without any luck. However, one of them is puzzling me.
If I perform this request :
var dataArray = [ { /* some plain object */ }, { /* another plain object */ ], ... ];
$.ajax(url, {
type: "post",
data: { models: dataArray }
});
Resulting a request data sent like
models[0][property1]:value1
models[0][property2]:value2
...
models[1][property1]:value3
models[0][property2]:value4
...
Unfortunately, the request is just not understood by .Net MVC4. Following a related SO question I've tried traditional: true
but the request sent to the server looks like this:
models:[object Object]
Which, obviously, sends not an object, but the string "[object Object]"
. ...What's wrong with this? Am I doomed to send serialized strings (and have to manually deserialize them on the server side) for every request involving non primitive parameters?
Note : this is my action method. As for now, everything I try results in
- the parameter is an array of the correct size, but each item is a new unmodified (empty) object or
the parameter is null
[HttpPost] public ActionResult UpdateModels(Models.SimpleModel[] models)