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.
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)