i am unable to get collection value during post in mvc 3. it is returning null.
$.post("/Work/Post", { vm: $('#myForm').serializeArray(), 'collection': ['a', 'b', 'c'] });
//Or
var data = $('#myForm').serializeArray();
data.push({ name: 'collection', value: ['a', 'b', 'c'] });
$.post("/Work/Post", data);
//Or
var data = $('#myForm').serializeArray();
data.push({ name: 'collection[]', value: ['a', 'b', 'c'] });
$.post("/Work/Post", data);
I had a similar problem when passing arrays.
Instead of using $.post
use $.ajax
and set the traditional
option = true
...
$.ajax({
type: "POST",
url: "Work/",
traditional: true,
data: { collection: ['a','b','c'] }
});
The traditional: true
option is important
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