我正在向 MVC 方法发送一条 JSON 消息。当我调试它调用该方法但似乎数据不存在。换句话说, answerDetail 为空。
有人可以就我可能做错的事情给我一些建议。这是我所拥有的:
以下 MVC 控制器方法:
[HttpPost]
[ActionName("CheckAnswers")]
public void CheckAnswers(AnswerDetail2 answerDetail)
{
var a = answerDetail;
}
这条消息被发送到方法:
POST http://127.0.0.1:81/api/Question/CheckAnswers HTTP/1.1
Host: 127.0.0.1:81
Connection: keep-alive
Content-Length: 722
Accept: application/json, text/plain, */*
Origin: http://127.0.0.1:81
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36
Content-Type: application/json;charset=UTF-8
Referer: http://127.0.0.1:81/questions/5
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Cookie: __RequestVerificationToken=4puG_e0..B181
[{"answerId":5,"text":"<p>x</p>","correct":null,"response":false},
{"answerId":6,"text":"<p>xx</p>","correct":null,"response":false},
{"answerId":7,"text":"<p>xxx</p>","correct":null,"response":false}]
这是我的 AnswerDetail2 类:
public class AnswerDetail2
{
public int answerId { get; set; }
public string text { get; set; }
public Nullable<bool> correct { get; set; }
public Nullable<bool> response { get; set; }
}
更新:请注意我更改了标题。它实际上是一个 Web API 方法,所以我认为发布一个对象是可以的。问题是它没有被接受。