Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

446
Visualizações
JSON data posts from Angular 2 front end to Asp.Net Core web api - loses values

I am sending values from an Angular 2 front end as visible here:

  censusManagementSearch(search: any): Observable<any> {
    let headers = new Headers({ 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem('token') });
        let options = new RequestOptions({ headers: headers });
    let body = JSON.stringify({ practice: search.practice, location: search.location, name: search.name });
    return this.http.post(this._api.apiUrl + 'censusmanagement', body, options)
      .map((response: Response) => {
        return response;
    })
      .catch((err: any) => {
        return Observable.throw(err.json().error || 'Server error');
    });
  }

Everything there is working fine. It's going to a C# back end as seen below. If it matters it's an ASP.Net core web api

[HttpPost]
public IActionResult PostCensusManagement([FromBody] int practice, int location, string name)

When I put a break point on this the values are 0 for the ints and "" for the string. I've tried taking [FromBody] out as well as replacing it with other options. Each time the values are blank.

Here is an image showing the values being sent in Chrome enter image description here

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I found the answer. I'll leave it here in case anyone else runs into this issue. In order for the web api to see the data I had to create a class for it.

public class CensusSearch
{
    public int location { get; set; }
    public int practice { get; set; }
    public string name { get; set; }
}

And changed the controller to this:

    [HttpPost]
    public IActionResult PostCensusManagement([FromBody] CensusSearch search)
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda