我有一个MVC操作,需要一个int(int [] ids)数组。我使用$ http的angularjs帖子,但每次发帖都会返回null
$http({
method: 'POST',
url: url,
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8;' },
data: $.param({
pcode: $scope.pcode,
bId: $scope.bId,
brandIds: [898,55],
regId: $scope.regId,
__RequestVerificationToken: getVerificationToken() // this is Html.Antiforgery that the action needs for posts
})
}).success(function (result) {});
我试过这个解决方案
AngularJs $http.post() does not send data
但如果我注入$ httpProvider,它会抛出注入错误。我使用angularjs 1.3
答案 0 :(得分:3)
$http({
method: 'POST',
url: url,
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8;' },
data: $.param({
pcode: $scope.pcode,
bId: $scope.bId,
brandIds: [898,55],
regId: $scope.regId,
__RequestVerificationToken: getVerificationToken() // this is Html.Antiforgery that the action needs for posts
},true)
}).success(function (result) {});
当您不提供该参数时,它将编码数组brandids []。你可以在request.form中看到这个。这不适用于mvc模型绑定。
如果您提供该值,则将数组编码为brandids。这就是mvc模型绑定器所需要的,所以它可以工作。