MVC4 大量刪除資料

來源:互聯網
上載者:User

標籤:資料   ini   ring   his   more   images   input   nbsp   string   

效果:

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: "../Logs/DeleteMore",
                    data: { ‘delitems‘: checkedList.toString() },
                    dataType: "text",
                    success: function (result) {
                        alert(result);
                        $("[name =‘RKEY‘]:checkbox").attr("checked", false);
                        window.location.reload();
                    }
                });
            }
        });
    });
</script>

HTML代碼:

  <table class="table table-bordered table-striped table-hover">
            <tbody>
                <tr align="center">
                    <td nowrap="nowrap" style="width: 120px; margin-left: 50px;">
                        <input type="checkbox" id="selectAll" name="selectAll" style="margin-left: 50px;" />
                        <input id="deleteBtn" type="button" role="button" class="btn btn-info btn-small" value="刪除" />
                    </td>
                    <td nowrap="nowrap"><strong>序號</strong></td>
                    <td nowrap="nowrap"><strong>日誌類型</strong></td>
                    <td nowrap="nowrap"><strong>操作使用者</strong></td>
                    <td nowrap="nowrap"><strong>登入IP</strong></td>
                    <td nowrap="nowrap"><strong>操作內容</strong></td>
                    <td nowrap="nowrap"><strong>操作時間</strong></td>
                    <td nowrap="nowrap"><strong>備忘</strong></td>
                </tr>
                @foreach (var item in Model)
                {
                    i++;
                    <tr align="center">
                        <td nowrap="nowrap"><input type="checkbox" id="RKEY" name="RKEY" value="@item.RKEY" /></td>
                        <td nowrap="nowrap">
                            @item.Counts
                        </td>
                        <td nowrap="nowrap">
                            @Html.DisplayFor(modelItem => item.LogType)
                        </td>
                        <td nowrap="nowrap">
                            @Html.DisplayFor(modelItem => item.UserAccount)
                        </td>
                        <td nowrap="nowrap">
                            @Html.DisplayFor(modelItem => item.LoginIP)
                        </td>
                        <td nowrap="nowrap">
                            @Html.DisplayFor(modelItem => item.Operation)
                        </td>
                        <td nowrap="nowrap">
                            @Html.DisplayFor(modelItem => item.CreateDate)
                        </td>
                        <td nowrap="nowrap">
                            @Html.DisplayFor(modelItem => item.Remark)
                        </td>
                    </tr>
                }
            </tbody>
        </table>

後台代碼:

    /// <summary>
        /// 大量刪除日誌資料
        /// </summary>
        /// <returns></returns>
        public ActionResult DeleteMore()
        {
            ArrayList arr = new ArrayList();
            string rkeyStr = "";
            StringBuilder sb = new StringBuilder();
            if (Request["delitems"] != null && Request["delitems"].ToString() != "")
            {
                rkeyStr = Request["delitems"].ToString();
                string[] rkeyArr = rkeyStr.Split(‘,‘);
                int count = 0;
                for (int i = 0; i < rkeyArr.Length; i++)
                {
                    string sqlStr = "delete from Logs where RKEY=" + Convert.ToInt32(rkeyArr[i]) + "";
                    count = SqlHelper.ExecuteSql(sqlStr);
                }
                if (count > 0)
                {
                    log.DeleteLogs("大量刪除日誌資料");
                    string str = "大量刪除成功!";
                    return Content(str);
                }
            }
            else
            {
                rkeyStr = "";
                string str = "大量刪除失敗!";
                return Content(str);
            }
            return null;
        }

 

MVC4 大量刪除資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.