zoukankan      html  css  js  c++  java
  • ajax 传递数组给后台.net MVC 控制器

    数组结构为: [ "5ae92c2786f3591b2cff1be5", "5ae91bb7ca673569a8d23a6e" ]

    前台代码:

     $.ajax({
                        type: "POST",
                        url: "/Registration/ManagementProject/DeleteProjectById",
                        dataType: "json",
                        data: {"selectData": that.UserIdArray },
                        async: false,
                        traditional: true,//这里设置为true
                        success: function (data) {
                            that.projectList = data;
                            console.log(data)
                            if (data.Response.ErrCode == "0") {
                                alert(data.Response.ErrMsg);
                                //清空已选择的数据
                                that.UserIdArray = [];
                                appList.GatProjectList(1);
                            }
                        }
                    });

    注意:

    注意:

    1、that.UserIdArray是一个数组

    2、ajax参数中data为{"selectData": that.UserIdArray }

    3、这种方式比较重要的就是traditional:true。或者将_list参数转换一下$.param(_list.true)。这里其实就是将_list作为传统的方式传递给后台,jQuery默认是做了转换的

    后台代码

     /// <summary>
           /// 根据选中Id 删除项目
           /// </summary>
           /// <param name="selectData">选中的项目数组  也可以是List<string></param>
           /// <returns></returns>
            public IActionResult DeleteProjectById(string [] selectData)
            {
            } 
  • 相关阅读:
    DAY10-MYSQL表操作
    DAY10-MYSQL完整性约束
    DAY10-MYSQL数据类型
    DAY10-MYSQL存储引擎
    DAY10-MYSQL库操作
    017.2 基本数据类型对象包装类
    017.1 stringBuffer
    016.2 String
    16.1 eclipse设置
    015.5线程常见用法(面试题)
  • 原文地址:https://www.cnblogs.com/happygx/p/8979472.html
Copyright © 2011-2022 走看看