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.idList.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));
            }
        }    
复制代码

 

         

posted @   Luckyfish小文  阅读(1009)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示