0
私は、PupilsScoresのリストを持つオブジェクトを送信するサーバーにhttp putメソッドを実行しています。コレクションを含む投稿されたオブジェクトがHTTP本文のコンテンツにバインドされていません
TestIdはバインドされていますが、PupilsScoresコレクションはnullです。
私も[FromBody]
を試しましたが、これはデフォルトのままにしておく必要があります。
なぜ私のPupilsScoresコレクションはnullですか?
CLIENT
updateTestAssignment(pupilsScores, testId) {
return this.http.put('/api/testassignments/' + testId, { pupilsScores: pupilsScores }).map(res => res.json());
}
サーバ
public class UpdateTestAssignmentRequestDto
{
public int TestId { get; set; }
public IEnumerable<PupilsScoresRequestDto> PupilsScores { get; set; }
}
[HttpPut("~/api/testassignments/{testId:int}")]
public async Task<IActionResult> Put(UpdateTestAssignmentRequestDto dto)
{
return NoContent();
}
RequestOptionsについて確認してください。 => http://stackoverflow.com/questions/37595980/angular-2-http-and-not-setting-content-type-application-json、とにかく、私は両方のオプションを試しても機能しません。 JSON stringifyは、content-typeがjsonの最後の2回のリリースではもう必要ありません。 – Pascal
OK [FromBody]の設定とjson.stringifyを明示的に混ぜていないが、このリンクに続いてRequestOptionsはありません。http://stackoverflow.com/questions/37595980/angular-2-http-and-not-setting-content-type -application-jsonはそれをついに実現しました。私はまた、ルートからのTestIdを再びPayloadに入れて、FromBodyとバインドする必要がありました。 – Pascal
RequestOptionsはここで言及されています。https://angular.io/docs/ts/latest/guide/server-communication.html – VahidN