我想使用angularjs HTTP post服務發送多個參數。如何用多個參數在angularjs中發送POST?
下面是客戶端代碼:
$http.post("http://localhost:53263/api/Products/", [$scope.product, $scope.product2]).
then(function (data, status, headers, config) { alert("success") },
function (data, status, headers, config) { alert("error") });
這裏是服務器端代碼:
// POST api/<controller>
public void Post([FromBody]Product product,[FromBody]Product product2)
{
var productRepository = new ProductRepository();
var newProduct = productRepository.Save(product);
}
但是,當我做後,我得到的錯誤。 任何想法我做錯了什麼?
我認爲你必須通過isArray:true在配置參數 –
請參見此[請參閱此鏈接](http://stackoverflow.com/questions/28829124/post-multiple-objects-from-angular-controller-to -web-api-2)哪些幫助我解決類似問題 –