zoukankan      html  css  js  c++  java
  • C#Mvc批量删除

    前台页面(JQuery)

    @*全选&批删*@
    <script type="text/javascript">
    $(document).ready(function () {
    // 全选
    $("#selectAll").click(function () {
    $("input[name='RKEY']").prop("checked", this.checked);
    });
    // 单选
    var subChk = $("input[name='RKEY']")
    subChk.click(function () {
    $("#selectAll").prop("checked", subChk.length == subChk.filter(":checked").length ? true : false);
    });
    /* 批量删除 */
    $("#DeleteBtn").click(function () {
    // 判断是否至少选择一项
    var checkedNum = $("input[name='RKEY']:checked").length;
    if (checkedNum == 0) {
    alert("至少选择一项!");
    return;
    }
    // 批量选择
    if (confirm("确定要删除所选项目?")) {
    var checkedList = new Array();
    $("input[name='RKEY']:checked").each(function () {
    checkedList.push($(this).val());
    });
    $.ajax({
    type: "POST",
    url: "/Home/V_Dels",
    data: { 'delitemsss': checkedList.toString() },
    dataType: "text",
    success: function (result) {
    alert(result);
    $("[name ='RKEY']:checkbox").attr("checked", false);
    window.location.reload();
    }
    });
    }
    });
    });
    </script>

    前台页面(H5)

    <table class="table table-hover" style="100%;font-size:30%;margin-top:1%;border-top:1px solid gray;border-left:1px solid gray;border-bottom:1px solid gray">
    <thead>
    <tr>
    <th> <input type="checkbox" id="selectAll" name="selectAll" style="" /></th>
    <td>ID</td>

    </tr>
    </thead>
    <tbody>
    @*显示*@
    @foreach (var item in Model)
    {
    <tr>
    <th><input type="checkbox" id="RKEY" name="RKEY" value="@item.V_Id" /></th>
    <td>@item.V_Id</td>
    </tr>
    }
    </tbody>
    </table>

    控制器

    //批量删除

    public ActionResult V_Dels()
    {
    ArrayList arr = new ArrayList();
    string rkeyStr = "";
    StringBuilder sb = new StringBuilder();
    if (Request["delitemsss"] != null && Request["delitemsss"].ToString() != "")
    {
    rkeyStr = Request["delitemsss"].ToString();
    string[] rkeyArr = rkeyStr.Split(',');
    int count = 0;
    for (int i = 0; i < rkeyArr.Length; i++)
    {
    count = bll.ValueTab_Del(Convert.ToInt32(rkeyArr[i]));
    }
    if (count > 0)
    {
    string str = "删除成功!";
    return Content(str);
    }
    else
    {
    rkeyStr = "";
    string str = "删除失败!";
    return Content(str);
    }
    }
    return null;
    }

  • 相关阅读:
    UVA11039
    UVA10970大块巧克力
    UVA10970大块巧克力
    UVA10340子序列
    UVA10340子序列
    UVA10382喷水装置
    UVA10382喷水装置
    UVA10020(最小区间覆盖)
    洛谷 P2141 珠心算测验
    UVa 11292 勇者斗恶龙(The Dragon of Loowater)
  • 原文地址:https://www.cnblogs.com/Dingcps/p/10267613.html
Copyright © 2011-2022 走看看