對checkbox進行多選刪除

 

1、View

$("#btnDelete").click(function () {

                var delString = "";   //獲取刪除id字符串

               //獲取選中的checkbox

                for (var i = 0; i < $("#txtPageNum").val() ; i++) {

                    if ($("#rptList_chkId_" + i).is(':checked') == true) {
                        delStr = $("#rptList_hidId_" + i).val();
                        delString += delStr + ",";
                    }

                }

             //操作

                if (delString != "") {
                    $.get("DelLawyer", { strId: delString }, function (data) {
                        if (data == "ok") {
                            window.location.replace("list");
                            alert("刪除成功");
                        }
                        else {
                            alert("刪除失敗");
                        }
                    }, 'text');
                }
                else {
                    alert("請選擇要刪除的項");
                }

            })


2、控制器

   public ActionResult DelLawyer(string strId)
        {
            try
            {
                string[] strArrs = strId.Split(',');
                for (int i = 0; i < strArrs.Length - 1; i++)
                {
                    //刪除具體操作
                    int delId = Convert.ToInt32(strArrs[i]);
                    UserDal.F_User_DelLawyer(delId);
                }
                return Content("ok");
            }
            catch (Exception ex)
            {
                return Content("刪除失敗"+ex.Message);
            }
        }



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章