axios post 回传数组至后台

就是简单的把值回传给后台,只不过值换成了数组而已,用原来FormData , URLSearchParams均不管用,折腾了半天

偶然看到这个帖子:https://blog.csdn.net/lee576/article/details/120347400,唉,原来就是这么简单!

前端代码:

//Vue  data中定义接收要删除id的数组 
data() {
            return {
                idList:[]
            }
        }
///批量删除用户
            delUser() {
                const length = this.multipleSelection.length;
                for (let i = 0; i < length; i++) {
                    this.delList.push(this.multipleSelection[i].OrderUserLogID);
                }
                this.$confirm('确定要删除用户吗?').then(_ => {
                    let _ids = this.idList;
                    //回传数组方法(数组格式:['1','2']):直接回传,无需赋参
                    axios.post('/CustomerInfo/Delete', _ids)
                        .then(res => {
                        if (res.data.success == true) {
                            this.$message({
                                message: res.data.message,
                                type: "success"
                            });
                            this.getUserList();
                        } else {
                            this.$message({
                                message: res.data.message,
                                type: "error"
                            });
                        }
                    })
                })
            }

后台代码:

       [HttpPost]
        public ActionResult Delete([FromBody] string[] ids)
        {
            if(ids.Length>0)
            {
                int[] idArray = Array.ConvertAll(ids,u=>int.Parse(u));
                foreach(int id in idArray)
                {
                    var model = userInfoIBll.GetEntityOne(u => u.OrderUserLogID==id);
                    userInfoIBll.Delete(model);
                }
                return Json(new ReturnJsonInfo(true, "用户信息删除成功!", null));
            }
            else
            {
                return Json(new ReturnJsonInfo(false, "用户信息删除失败!", null));
            }
        }    

 

         

上一篇:matlab和C/C++混合编程--Mex


下一篇:promise等待多个异步请求完毕后再执行其他代码的方法