ajax将IList发送给控制器

时间:2017-12-09 14:44:09

标签: c# jquery ajax

我似乎无法弄清楚如何将数据发送到具有IList的控制器。在我的例子中,我的C#看起来像:

    public ICollection<KeyValuePair<int, SaveStatus>> StatusUpload(IList<StatusModel> status, int id)
    {
        var statusList = new List<KeyValuePair<int, SaveStatus>>();
        var mainStuff = UnitOfWork.MainRespository.GetAll();
        var subStuff= UnitOfWork.SubRepository.GetAll();
        for (var i = 0; i < addresses.Count; i++)... etc...

我发送给控制器的是:

$.ajax({
    type: 'POST',
    url: '/MainController/StatusUpload',
    data: { status: status }
}).done(function(results){
    console.log(results);
})

和status由此对象组成:

var status = [];
var innerAddresses = {
        First: first,
        Second: second,
        Third: third,
}
status.push(innerStatus);

状态结果如下:

0: { First: 1, Second: second, Third: 2},
1: { First: 2, Second: second, Third: 3},
2: { First: 3, Second: second, Third: 4}

0 个答案:

没有答案