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

  • 相关阅读:
    Android——继续深造——从安装Android Studio 2.0开始(详)
    PHP——安装wampserver丢失MSVCR110.dll
    Marza Gift for GDC 2016
    Retrieve OpenGL Context from Qt 5.5 on OSX
    Space Time Varying Color Palette
    Screen Space Depth Varying Glow based on Heat Diffusion
    Visualization of Detail Point Set by Local Algebraic Sphere Fitting
    Glass Dragon
    Jump Flood Algorithms for Centroidal Voronoi Tessellation
    京都之行
  • 原文地址:https://www.cnblogs.com/Dingcps/p/10267613.html
Copyright © 2011-2022 走看看