微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

asp.net mvc 接收jquery ajax发送的数组对象

<script type="text/javascript">
        $(function () {
            var obj = { name: "军需品", myclass: [{
                one: 1,
                two: 2,
                three: 3
            }, {
                one: 11,
                two: 22,
                three: 33
            }, {
                one: 111,
                two: 222,
                three: 333
            }]
            };

            $.ajax({
                url: '<%=Url.Content("~/Home/GetList") %>',
                type: 'POST',
                dataType: 'json',
                data: JSON.stringify(obj),
                contentType: 'application/json; charset=utf-8',
                success: function (data, state) {
                    alert(JSON.stringify(data));
                    alert(state);
                }
            });
        });
    </script>
前端Jquery Ajax请求

 1 public class HomeController : Controller
 2     {
 3         //
 4         // GET: /Home/
 5 
 6         public ActionResult Index()
 7         {
 8             return View();
 9         }
10 
11         public ActionResult GetList(Myobj a)
12         {
13             return Json(a);
14         }
15     }
16 
17     public class Myobj
18     {
19         public string name { get; set; }
20         public List<MyClass> myclass { get; set; }
21     }
22 
23     public class MyClass
24     {
25         public int one { get; set; }
26         public int two { get; set; }
27         public int three { get; set; }
28     }
asp.net mvc后端接收

 

 注意:集合的名称必须相同

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐