[我试图弄清楚为什么我无法将JSON对象发送到后端api。给定以下代码,我可以命中api端点,但Name: Test
从未进入控制器:
Angular http请求:
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);
}
我的TestViewModel
看起来像这样:
public class TestViewModel
{
public string Name { get; set; }
}
此设置中是否缺少基本功能?
使用[FromBody]
public ... ([FromBody] TestViewModel newSportType)
{
}