Consider that I have the following javascript that do a post:
$.post("/MyController/SomeAction",
{ myParam: ['Filip', 'Ekberg'] }, function(data) { alert(data); }, "html");
My Action looks like this:
[HttpPost]
public ActionResult SomeAction(FormCollection collection,
IEnumerable<string> myParam)
{
return null;
}
When I enter this Action, myParam is null, if I expand the FormCollection I see this:

The weird part here is that the name ( Key ) is myParam[] which might be why it is not mapped to myParam.
Also, I tried doing dynamic[] myParam as well, but it doesn't work either.
I know that I can use JSON.stringify but I don't want to do that now. So, any ideas what's going on here and if there is a solution?
Try setting the traditional parameter to true:
$.ajax({
url: '/MyController/SomeAction',
type: 'POST',
data: { myParam: [ 'Filip', 'Ekberg' ] },
traditional: true,
success: function(data) {
alert(data);
}
});
Also you can safely remove the FormCollection parameter from your POST action signature. It's useless.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With