我在 mvc 3 中发布期间无法获得收藏值(value)。 它返回 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);
最佳答案
我在传递数组时遇到了类似的问题。
不要使用 $.post
,而是使用 $.ajax
并设置 traditional
选项 = true
.. .
$.ajax({
type: "POST",
url: "Work/",
traditional: true,
data: { collection: ['a','b','c'] }
});
traditional: true
选项很重要
关于带有序列化和数据数组的 jQuery post(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11868051/