Request arrives null in C #

3

I have a request that is being made this way in angle 5.

enviarEmail(titulo: TitulosCobranca, unidade: UnidadeEmpresa) {
    let param: any = {
      titulo: titulo,
      unidade: unidade
    }

    return this.http.post(this.UrlService + '/TitulosCobranca/envio', param)
      .map((res: any) => res.data);
}

In C # I'm trying to get the data as follows:

[HttpPost]
[Route(*_minhaRota_*)]
public async Task<IActionResult> EnviarEmail([FromBody] ParametrosPesquisaViewModel param)
{
    UnidadesEmpresaViewModel unidadeEmpresa = param.unidade;
    TitulosCobrancaViewModel titulo = param.titulo;
    /* Continue ... */

When I put the breakpoint and I'll figure out what's happening, the value of param is null .

Placing the console.log before the request the data is there.

Below the request body print:

publicclassParametrosPesquisaViewModel{publicintIndex{get;set;}=1;publicstringSearch{get;set;}="";

        public string Order { get; set; } = "";

        public string razaoSocial { get; set; }

        public string cnpj { get; set; }

        public string telefone { get; set; }

        public int pagina { get; set; }

        public int nrRegistros { get; set; }

        public ParamConsultaViewModel Param { get; set; }

        public UnidadesEmpresaViewModel unidade { get; set; }

        public TitulosCobrancaViewModel titulo { get; set; }
    }

Above is my Model.

Does anyone have a light to give me?

    
asked by anonymous 18.05.2018 / 13:59

1 answer

1

I was able to solve the problem by executing the request with an object itself by mounting it on the request only with the fields that were of interest to me, capture in the back end, in case without passing the complete object.

enviarEmail(titulo: TitulosCobranca, unidade: UnidadeEmpresa) {
    let param: Object = {
        "Titulo": {
            id: titulo.id
        }, 
        "Unidade": {
            id: unidade.id,
            email: unidade.Email
        } 
    }

    return this.http.post(this.UrlService + 'TitulosCobranca/envio', param)
        .map((res: any) => res.data);
}
    
18.05.2018 / 16:31