ASP.NET MVC AJAX提交LIST数据

1.ajax前台代码

<script>
    $(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);
        }
    }); 
});



   
</script>

2.C#后台代码

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

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

猜你喜欢

转载自blog.csdn.net/qq_40098572/article/details/104352747
今日推荐