MVC4 批量删除数据

效果:

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

时间: 2024-11-18 22:50:49

MVC4 批量删除数据的相关文章

ajax批量删除数据

做网页经常要选择批量删除数据,基本都是异步请求批量删除,用到更多的是ajax批量删除.思路是前端ajax请求,传入ids(要删除对象id的字符串数组)到后台. 后台再遍历id,调用删除接口,删除数据.返回json给前台. 代码例子如下: 1 function deleteSaleChance() { 2 var selectedRows = $("#dg").datagrid("getSelections"); 3 if(selectedRows.length==0

bulk批量删除数据

bulk批量删除数据 1.  案列介绍 需要在一个1亿行的大表中,删除1千万行数据 需求是在对数据库其他应用影响最小的情况下,以最快的速度完成 如果业务无法停止的话,可以参考下列思路: 根据ROWID分片.再利用Rowid排序.批量处理.回表删除 在业务无法停止的时候,选择这种方式,的确是最好的 一般可以控制在每一万行以内提交一次,不会对回滚段造成太大压力 我在做大DML时,通常选择一两千行一提交 选择业务低峰时做,对应用也不至于有太大影响 2.  代码实现 测试环境 drop table t_

crm使用soap批量删除数据

//批量删除数据 function demo() { //实体名称 var entityname = "fw_student"; var data = []; data.push("8B1D93C6-BF1E-E411-9406-00155D005802"); data.push("20718494-0C2C-E411-9407-00155D005802"); executemultipleDelete(entityname, data); }

批量删除数据表

方法一:DeleteForm表名 方法二:TRUNCATETABLE在功能上与不带WHERE子句的DELETE语句相同:二者均删除表中的全部行.但TRUNCATETABLE比DELETE速度快,且使用的系统和事务日志资源少.DELETE语句每次删除一行,并在事务日志中为所删除的每行记录一项.TRUNCATETABLE通过释放存储表数据所用的数据页来删除数据,并且只在事务日志中记录页的释放.TRUNCATETABLE删除表中的所有行,但表结构及其列.约束.索引等保持不变.新行标识所用的计数值重置为

Hbase之批量删除数据

import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.ConnectionFactory; impor

ssm框架下怎么批量删除数据?

ssm框架下批量删除怎么删除? 1.单击删除按钮选中选项后,跳转到js函数,由函数处理 2. 主要就是前端的操作 js 操作(如何全选?如何把选中的数据传到Controller中) 3.fun()函数(前端) /*添加删除选中栏*/ function fun(){ //给删除选中按钮添加单击事件 document.getElementById("delSelected").onclick = function(){ if(confirm("您确定要删除选中条目吗?"

asp+jquery实现批量删除数据

该方法优点是可以在同一页面既做查询又可删除,删除时用jquery改变form表单action的值 1.查询列表页: <script> //判断全选函数 function selectall(v){ var f=document.forms["form"] for (i=0;i<f.elements.length;i++) if(f.elements[i].name=="id") f.elements[i].checked=v; } //绑定删除时间

mysql动态执行sql批量删除数据

CREATE PROCEDURE `sp_delete_pushmsg_data`() BEGIN declare l_delete_date varchar(16); declare l_state_date varchar(16); declare l_dutyno int; declare l_row_cnt int DEFAULT 0; declare rn int default 0; declare i int default 0; set l_dutyno=101; set l_d

SQL 批量删除数据表

declare @name varchar(200) while(exists(select * from sysobjects where name like '表名前缀%')) begin select @name=name from sysobjects where name like '表名前缀%' exec ('drop table '+@name) end