其他分享
首页 > 其他分享> > axios post 回传数组至后台

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

 

         

标签:axios,删除,res,ids,数组,回传,post,data,message
来源: https://www.cnblogs.com/Craft001wen/p/15870203.html