我无法将数组从angularJS传递到mvc4中的web api动作。将数组传递给web api AngularJS
我的$资源是:
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);
}
};
我的API动作之后调用save在AngularJS中的操作:
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);
}
我的萤火得到一个错误:“不能绑定多个参数(‘模型’和‘MODEL1’)请求的内容”
此代码做工精细,如果我dont't通阵列presentationItemList从角度和不映射它在模型1参数的web API动作。
请帮帮我!
您的资源如何注入?你能告诉我们你的整个控制器吗? (1)你的'presentationItemList'没有在'$ scope'中定义? (2)如果您正在使用您的资源,为什么要调用'$ scope.presentation。$ save'? '$ save',如果你正在使用你的资源,应该只是'save'; – Beterraba