zoukankan      html  css  js  c++  java
  • 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后端接收

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

  • 相关阅读:
    Linux命令(一)
    数据库SQL学习(一)
    Eclipse
    VsCode支持的markdown语法参考(一)
    常用算法Tricks(一)
    dispose方法的使用
    收藏一个链接
    我还不知道取什么名字
    NioSocket的用法
    随便乱塞塞2~
  • 原文地址:https://www.cnblogs.com/jxp0202/p/12742244.html
Copyright © 2011-2022 走看看