I thought MVC3 can bind JSON data to model by default.
but this code
server:
[HttpPost]
public ActionResult Save(IList<int> IDs)
{
return null;
}
client:
$.post('@Url.Action("Save", "Users")', {'IDs' : [1, 2, 3]}, function() {});
don't work. Why ??
You need to send your data as application/json:
You have to apply
JSON.stringify
Your code sends
IDs[]=1&IDs[]=2&IDs[]=3
.You need send
IDs=1&IDs=2&IDs=3
.Set
traditional:true
parameter to use the traditional style of param serialization.This might be the same as the problem I ran into a while ago. Check out this SO question Post Array as JSON to MVC Controller