![](/img/trans.png)
[英]Having trouble passing complex model to controller through ajax call
[英]Having trouble passing a dictionary from jQuery to Controller
控制器:
[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键/值的字典:
对于字典,您需要同时具有键和值属性,例如:
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) {
}
});
希望能帮助到你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.