我无法将数组从 angularJS 传递到 mvc4 中的 web api 操作。
我的 $resource 是:
adminApp.factory('presentation', ['$resource',
function ($resource) {
return $resource('/api/presentation/:id', { id: '@id' },
{
update: { method: 'PUT', params: { id: '@id' } },
save: { method: 'POST', params: { model1: '@model1' } },
remove: { method: 'DELETE', params: { id: '@id' } }
}
);
}]);
用于传递数据数组以保存它的AngularJS代码(我要传递的presentationItemList ):
$scope.savePresentation = function() {
if ($scope.form.$valid) {
if ($scope.presentation.Id != undefined && $scope.presentation.Id > 0) {
$scope.presentation.$update({ id: $scope.presentation.Id });
} else {
$scope.presentation.$save({ model1: presentationItemList });
}
} else {
$scope.addFormValidationAlert($scope.form);
}
};
我在 AngularJS 中保存操作后调用的 Api 操作:
public HttpResponseMessage Post(PresentationItemModel model, List<PresentationElementInfoModel> model1)
{
var item = Mapper.Map<PresentationItemModel, Presentation>(model);
model.Id = GetActionResultData(ServiceDataProvider.PresentationCrudService.SaveOrUpdate(item));
if (model.Id.MoreThanZero())
{
return new HttpResponseMessage(HttpStatusCode.Accepted)
{
Content = new ObjectContent<PresentationItemModel>(model,
new JsonMediaTypeFormatter())
};
}
throw new HttpResponseException(HttpStatusCode.NotFound);
}
我在萤火虫中收到错误:“无法将多个参数('model'和'model1')绑定到请求的内容”
此代码工作正常,如果我不从角度传递数组presentationItemList并且不将其映射到web api 操作的model1参数中。
请帮我!