Posting an array of ints to my MVC controller seems to result in the value being null.
The form data (parsed), indicates that each element in the array is posted individually:
ids[]:39
ids[]:54
Which seems to make sense as I read that form data can only be posted as key/value pairs.
My controller action is defined as follows:
[HttpPost]
[Authorize]
public JSONResult SubmitApprovedUploadedPhotoIds(List<int> ids)
{
try
{
if (ids == null)
throw new ArgumentNullException("ids");
// ...
}
// ...
}
The main portion of my ajax POST:
// `ids` is an array of ints
$.ajax({
url: "/MyController/SubmitApprovedUploadedPhotoIds",
cache: false,
data:
{
ids: ids
},
dataType: "json",
type: "POST",
});
I would like the array of posted ids to populate the ids variable in the MVC action.
I have tried changing the post code to:
{
ids: $(ids).serializeArray()
},
and have tried changing my MVC action to:
public JSONResult SubmitApprovedUploadedPhotoIds(int[] ids)
with no success.