Reputation: 2136
Im trying to figure out why I am not able to send down a JSON object to my back-end api. Given the following code I can hit my api endpoint but the Name: Test
is never making it to the controller:
Angular http request:
addSport(newSportType: SportType): Observable<SportType> {
const headers = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
};
return this.http.post<SportType>('/sport-type', JSON.stringify({ Name: 'Test' }), headers);
}
My TestViewModel
looks like this:
public class TestViewModel
{
public string Name { get; set; }
}
Is there something basic I am missing in this set up?
Upvotes: 0
Views: 169
Reputation: 963
use [FromBody]
public ... ([FromBody]TestViewModel newSportType)
{
}
Upvotes: 2