控制器:
[HttpPost]
public void SubmitUserPicks(Dictionary<string,string> data)
{
}
Jquery的:
var listOfPicks = [{gameID : "2", teamID : "3"}];
$.ajax({
type: "POST",
traditional:true,
url: "SubmitUserPicks",
content: "application/json",
dataType: "json",
data: listOfPicks,
success: function (result) {
}
});
但由于某种原因,传递的是具有Action和Controller的键/值的字典:
答案 0 :(得分:1)
对于词典,您需要具有键和值属性,例如:
data['myDictionary[0].Key'] = "gameID";
data['myDictionary[0].Value'] = 2;
data['myDictionary[1].Key'] = "teamID ";
data['myDictionary[1].Value'] = 3;
然后您可以将data
发送到服务器:
$.ajax({
type: "POST",
traditional:true,
url: "SubmitUserPicks",
content: "application/json",
dataType: "json",
data: data,
success: function (result) {
}
});
希望有所帮助