0
2つのオブジェクトをAngular 2を使用してAspNetCore WebAPIエンドポイントにPOSTしようとしています。ボディストリームを使用してコンテンツを正常に抽出できました。ASP.NET Core WebAPIに2つ以上のオブジェクトをPOSTする方法
これを実現するより洗練された方法がありますか?
[HttpPost]
[ActionNameAttribute("complex2objects")]
public User ComplexTwoObjects(){
var body = Helpers.Request.ExtractBody(this.Request.Body);
var obj1 = Helpers.Request.GetBodyObject(body,0,new User());
var obj2 = Helpers.Request.GetBodyObject(body,1,new User());
return obj2;
}
...
public static string ExtractBody(Stream body){
StreamReader reader = new StreamReader(body);
return reader.ReadToEnd();
}
public static T GetBodyObject<T>(string content, int index,T type){
var composite = JsonConvert.DeserializeObject<IList>(content);
return JsonConvert.DeserializeAnonymousType(composite[index].ToString(),type);
}
複雑なオブジェクト解析を.Net Core/WebAPIにオフロードする機会はありますか?
POSTデータはどのように見えますか? –
[{"" prop1 ":1234"}、{"prop2_Of_SecondObject": "1234"}] – Tony
モデルバインダーがあなたのために苦労していると確信しています。配列ユーザーの/ IEnumerableを –