Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

444
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!