How to send POST in angularjs with multiple params?

Client Side

Data needs to be grouped in an object array as payload – Indata:

var Indata = {'product': $scope.product, 'product2': $scope.product2 };

Pass the payload through $ as the second argument:

$"http://localhost:53263/api/Products/", Indata).then(function (data, status, headers, config) { 
},function (data, status, headers, config) { 

Server Side

Create a Data Transfer Object(DTO) class as such:

public class ExampleRequest {
   public string product {get; set;};
   public string product2 {get; set;};

The class below accepts DTO with the same property names which the payload is carrying.

public void Post(ExampleRequest request)
    var productRepository = new ProductRepository();
    var newProduct = productRepository.Save(request.product);

In above class, request contains 2 properties with values of product and product2

Leave a Comment