0
JSONデータをMVC5アクションにPOSTする方法はありますか? WebAPIではありません!JSONからASP.NET MVC5へのPOST? (Web APIではない)
問題は:私のアクションは呼び出されますが、着信モデルのすべてのプロパティはnullです。
モデル:
using Newtonsoft.Json;
[JsonObject()]
[Serializable()]
public class DemoModel
{
[JsonProperty()]
public string a { get; set; }
[JsonProperty()]
public string b { get; set; }
}
アクションは次のとおりです。私はリクエストをシミュレートするフィドラーを使用している
[HttpPost()]
public ActionResult demoaction(DemoModel model)
{
//model.a here is null, should be "AAA"
//model.b here is null, should be "BBB"
}
。私のPOSTリクエストは、次のようになります
POST http://localhost:9000/demoaction HTTP/1.1
Host: localhost:9000
Connection: keep-alive
Accept: */*
Content-Type: application/json
Content-Length: 60
と体は次のようになります。
{"a":"AAA","b":"BBB"}
だから、質問再び:どのように私はアクションにJSONを投稿することができますか?私の場合、モデルのすべてのプロパティはnullです。
FromBody属性があるだろうことなしに、あなたのPOSTリクエストヘッダ内の
Content-Type : application/json
を使用していることを確認し非WebAPIでは利用できません:/ – Dimaあなたは正しいです。謝罪いたします – Nkosi