O.MeeKoh
O.MeeKoh

Reputation: 2136

Property Binding in ASP.NET Core NOT binding property values to view model

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);
    }

enter image description here

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

Answers (1)

anıl yıldırım
anıl yıldırım

Reputation: 963

use [FromBody]

public ... ([FromBody]TestViewModel newSportType)
{

}

Upvotes: 2

Related Questions