How to send 1 object and 1 vector to an API in C # with $ http.post?

1

In my application I created an API in C #, which is consumed by my web application in Angular. I need to pass 1 object and 1 vector as parameters to the API, but the content comes empty in the API, how to solve?

Here are my codes:

Part of JavaScript:

    $scope.Exportar = function () {

   var listProdutos = {
       ListaCompraVenda : {listacompravenda: $scope.modelcompraevenda.listProdutos},
       ListaMeses : {meses:[$scope.dataBase.data1,
       $scope.dataBase.data2,
       $scope.dataBase.data3,
       $scope.dataBase.data4,
       $scope.dataBase.data5,
       $scope.dataBase.data6,
       $scope.dataBase.data7,
       $scope.dataBase.data8,
       $scope.dataBase.data9,
       $scope.dataBase.data10,
       $scope.dataBase.data11,
       $scope.dataBase.data12]}
    };


    $http.post($rootScope.raiz_ws + "/local/funcao", listProdutos )
     .then(function (response) {
        }); 
    };

Controller in C #

 [HttpPost]
    [Route("funcao")]
    public HttpResponseMessage Gerar(Classe listProdutos)
    {..}

C # Class:

public class Classe
{
    public List<CompraeVenda> ListaCompraVenda { get; set; }
    public List<string> ListaMeses { get; set; }

}
    
asked by anonymous 24.10.2017 / 16:12

2 answers

1

I was able to solve by changing only my var listProducts

var listProdutos = {
        ListaCompraVenda: $scope.modelcompraevenda.listProdutos,
        ListaMeses: [$scope.dataBase.data1,
        $scope.dataBase.data2,
        $scope.dataBase.data3,
        $scope.dataBase.data4,
        $scope.dataBase.data5,
        $scope.dataBase.data6,
        $scope.dataBase.data7,
        $scope.dataBase.data8,
        $scope.dataBase.data9,
        $scope.dataBase.data10,
        $scope.dataBase.data11,
        $scope.dataBase.data12]
    };
    
24.10.2017 / 20:14
0

Try to put [FromBody] pro parameter to be passed in the body of the Request:

public HttpResponseMessage Gerar([FromBody]Classe listProdutos)
    
24.10.2017 / 16:16