I can't pass array from angularJS to web api action in mvc4.
My $resource is:
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 code for pass array of data to save it(presentationItemList that I want to pass):
$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);
}
};
My Api action that call after save action in 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);
}
I get an error in firebug: "Can't bind multiple parameters ('model' and 'model1') to the request's content"
This code work fine,if I dont't pass array presentationItemList from angular and don't map it in model1 param of web api action.
Please, help me!
presentationItemListisn't defined in your$scope?; (2) If you are using your resource, why you call$scope.presentation.$save? That$save, if you are using your resource, should be justsave;