Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

447
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda