AJAX:
function systemsChanged(elem)
{
var items = [];
for (i = 0; i < elem.length; i++)
if (elem[i].selected) {
items.push(elem[i].value);
}
var post = { ids: items };
$.ajax({
type: "POST",
traditional: true,
url: "@Url.Action("LoadApplicationConfigs", "Application")",
content: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify(post),
success: function (d) {
alert(d.message);
},
error: function (xhr, textStatus, errorThrown) {
alert("não rolo");
}
});
}
C#MVC 4:
[HttpPost]
public JsonResult LoadApplicationConfigs(IList<string> ids)
{
object data = new
{
message = "aha!"
};
return new JsonResult() { Data = data };
}
它输入了post方法,但ids
设置为null
。我也尝试将ids
更改为string[]
,但未成功。返回ajax很好:它显示了&#34; aha!&#34;警报。我似乎无法为mvc活页夹提供准确的格式。有什么想法吗?
答案 0 :(得分:1)
更新您对此的ajax调用:
$.ajax({
type: "POST",
traditional: true,
url: "@Url.Action("LoadApplicationConfigs", "Application")",
content: "application/json; charset=utf-8",
dataType: "json",
data: post,
success: function(d) {
alert(d.message);
},
error: function(xhr, textStatus, errorThrown) {
alert("não rolo");
}
});
这可以使用或不使用traditional
选项。