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)
        {
        } 

猜你喜欢

转载自www.cnblogs.com/happygx/p/8979472.html