【发布时间】:2013-09-19 09:07:28
【问题描述】:
好的,我已经看到很多关于这个问题的问题,但没有一个答案对我真正有用,这是我的 AJAX:
$.ajax({
url: "/FilterSessions/GetFilterSession",
type: "GET",
dataType: "json",
data: jsonFilters,
traditional: true,
success: function (response) {
//Haha, it's never entering here. not really.
}
});
var "jsonFilters" 包含一个包含以下数据的数组:
[0] = { Path: "Test", Name: "More testing", Value: "Test Value" },
[1] = { Path: "Test", Name: "More testing", Value: "Test Value" }
这是我的控制器:
public ActionResult GetFilterSession(List<FilterSessionModel> jsonFilters)
{
//Do things
return Json(false, JsonRequestBehavior.AllowGet);
}
jsonFilters 始终保持为空...我也尝试将 contentType: "application/json; charset=utf-8" 添加到 AJAX 调用...但这并没有真正做任何事情
最后,FilterSessionModel 类的结构如下:
public class FilterSessionModel
{
public string Path { get; set; }
public string Name { get; set; }
public string Value { get; set; }
}
关于我可能缺少什么或可能发生什么的任何想法?
到目前为止我尝试过的事情:
设置“traditional: true”、设置“contentType”、使用 JSON.stringify 并尝试在 MVC 控制器中接受字符串(不可行)
更新:感谢下面的答案,我意识到缺少的是使用参数 ID 发送数据,如下所示:
data: "{param1ID:"+ param1Val+"}"
【问题讨论】:
标签: c# jquery ajax asp.net-mvc