【发布时间】:2017-10-31 11:36:41
【问题描述】:
我在Controller上有以下方法:
public ActionResult TestMultipleParameters(IEnumerable<TestM> competences, IEnumerable<long> extracompetences)
{
return Json("success", JsonRequestBehavior.AllowGet);
}
对象是:
public class TestM
{
public string uid { get; set; }
public long Id { get; set; }
public bool IsFromParent { get; set; }
}
从查询中我想发送这个:
var competences = [ {uid: "a", Id: 1, IsFromParent: true}, {uid: "b", Id: 2, IsFromParent: false}];
var extraCompetences = [1, 2, 3];
jQuery.ajaxSettings.traditional = true;
$.ajax({
url: ...,
async: true,
data: JSON.stringify({ competences: competences, extracompetences: extracompetences }),
dataType: 'json',
contentType: 'application/json; charset=utf-8',
type: 'GET',
error: handleException,
success: function(data){
console.log("success");
}
})
我尝试了 JSON.stringify 和 not stringify 之间的许多组合,但数据没有发送到 MVC。如果没有 JSON.stringify,则将数组发送到控制器,但 TestM 的值是默认值。
【问题讨论】:
标签: jquery json asp.net-mvc