I have the following controller that I am posting to in a form via AJAX:
[HttpPost]
public ActionResult Create(List<int> listOfSTuff)
{
try
{
service.Create(listOfSTuff);
}
catch
{
return null;
}
return Json(new { gid = g.ID });
}
I am having a hard time with my jQuery AJAX post making the datatypes compatible. Here is my jQuery/JavaScript code:
var listOfStuff = [1, 2, 3];
$ .ajax({
type: 'POST',
url: '/MyController/Create',
data: listOfStuff,
success: function(data) {
alert(data.gid);
},
error: alert(':('),
dataType: 'json'
});
I know that the AJAX post to the controller is working because I get a gid
but I do not see the array elements 1
or 2
or 3
saved in the database. It does not appear that the controller likes my JavaScript array that is being passed over. Can anyone suggest how the data structure should look like from the frontend?