C# 实现批量删除功能

2021-01-03 09:27

阅读:452

标签:rip   NPU   class   hang   code   join   inpu   rem   ati   

input type="submit" class="btn btn-info" onclick="DelAll()" value="批量删除" />
 table class="table table-striped" id="table">
        tr>
            td>input id="cb_selAll" type="checkbox" />td>
            td>IDtd>
        tr>
        tbody id="tb_body">
            @foreach (var item in Model)
            {
                tr>
                    td>input type="checkbox" value="@item.id" class="cb_fruit" />td>
                    td id="id">@item.idtd>
                tr>
            }
        tbody>
    table>
script>
    $(function () {
        $("#cb_selAll").change(function () {
            $("#tb_body :checkbox").prop("checked", this.checked);
        });
    });
    function DelAll() {
        var id = [];
        $("#tb_body :checkbox:checked").each(function () {
            id.push($(this).val());
        });
        $.ajax({
            url: "/Employees/DelAll",
            type: "GET",
            data: { id: id.join(",") },
            success: function (data) {
                if (data > 0) {
                    alert("成功!");
                    $("#tb_body :checkbox:checked").parent().parent().remove();
                    location.reload();
                } else {
                    alert("失败!");
                }
            },
            error: function () {
                alert("系统繁忙!");
            }
        });
    }
script>
        /// 
        /// DelAll
        /// 
        /// 
        /// 
        [HttpGet]
        public int DelAll(string id = "0")
        {
            string[] datalist = id.Split(,);//定义数组
            Liststring> list = new Liststring>();
            foreach (var item in datalist)
            {
                string data = "" + item.ToString() + "";
                list.Add(data);
            }
            string sql = string.Format("delete from Table where Id in(" + string.Join(",", list) + ")", list);
            return db.ExecuteNonQuery(sql);
        }

 

C# 实现批量删除功能

标签:rip   NPU   class   hang   code   join   inpu   rem   ati   

原文地址:https://www.cnblogs.com/BlackAgg/p/13207806.html


评论


亲,登录后才可以留言!