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

 

         


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM