0
有没有办法将JSON数据发布到MVC5动作? 不是WebAPI!POST JSON到ASP.NET MVC5? (不是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属性不适用于非WebAPI:/ – Dima
您是对的。我很抱歉 – Nkosi