C# 대량 제거 기능 구현

12323 단어
<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(',');// List<string> list = new List<string>(); 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); }

좋은 웹페이지 즐겨찾기