.net mvc ajax list post

http://stackoverflow.com/questions/13242414/passing-a-list-of-objects-into-an-mvc-controller-method-using-jquery-ajax

ajax 传递集合 给 mvc 的Action

$(document).ready(function () {
    var things = [
        { id: 1, color: yellow },
        { id: 2, color: blue },
        { id: 3, color: red }
    ];      

    things = JSON.stringify({ things: things });

    $.ajax({
        contentType: application/json; charset=utf-8,
        dataType: json,
        type: POST,
        url: /Home/PassThings,
        data: things,
        success: function () {          
            $(#result).html("PassThings()" successfully called.);
        },
        failure: function (response) {          
            $(#result).html(response);
        }
    }); 
});


public void PassThings(List<Thing> things)
{
    var t = things;
}

public class Thing
{
    public int Id { get; set; }
    public string Color { get; set; }
}

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。