您的位置:首页 > Web前端 > JavaScript

JS多选删除,提交到后台MVC的action操作

2013-08-24 11:29 288 查看
--------------------------JS分割线------------------------------------------------

<script type="text/javascript">

    // 提交到后台操作删除

    function OnDelete() {

        var ids = "";

        $("input:checked").each(function () {

            ids = ids + $(this).val() + ",";

        });

        if (ids.length > 0) {

            if (confirm("确定删除吗?")) {

                var url = "/Set_Business/DeleteAll?ids=" + ids;

                $.getJSON(url, function (data) {

                    if (data) {

                        window.location.reload();

                        alert("删除成功!");

                    }

                    else {

                        alert("操作发生异常,删除成功!");

                    }

                })

            }

        } else {

            alert("请选择数据!");

        }

    }

 

   // 标题行的checkbox, name为checkAll,数据行的的checkbox,name为selectFlag

    $(function () {

        //选中全部

        $("#checkAll").click(function () {

            if (this.checked) {

                $("input[name='selectFlag']:checkbox").each(function () { //遍历所有的name为selectFlag的 checkbox  

                    $(this).attr("checked", true);

                })

            }

            else if (!this.checked) {

                $("input[name='selectFlag']:checkbox").each(function () { //遍历所有的name为selectFlag的 checkbox  

                    $(this).attr("checked", false);

                })

            }

        })

        //取消全选   

        //                $("#delCheckAll").click(function () {

        //                    if (this.checked) {

        //                        $("input[name='selectFlag']:checkbox").each(function () { //遍历所有的name为selectFlag的 checkbox  

        //                            $(this).attr("checked", false);

        //                        })

        //                    }

        //                })

    });

--------------------------有数据绑定的html分割线------------------------------------------------

                    <div class="top-btn">

                        <a  href="/Set_Business/BusinessDel" onclick="OnDelete()">删除</a>

                       

                    </div>

                    <table cellspacing="0" cellpadding="0" class="tb-entList">

                    <tr>

                        <th style="width: 24px;"><input class="check-box" name="checkAll" id="checkAll" type="checkbox" value="true"/></th>

                        <th style="width: 70px;">业务标题</th>

                      <th style="width: 70px;">创建人</th>

                        <th style="width: 80px;">创建时间</th>

                    </tr>

                    @if (businessList != null && businessList.Count > 0)

                    {

                        foreach (var item in businessList)

                        {

                        <tr>

                            <td><input class="check-box" type="checkbox"  name="selectFlag" value="@item.BusinessID" /></td>

                            <td>@item.BusinessTitle</td>

                            <td>@item.CreateUserName</td>

                        </tr>

                        }

                    }

                    else

                    {

                     <tr><td colspan="11"> 暂无数据</td></tr>  

                    }

                </table>

 

--------------------------后台处理分割线------------------------------------------------

        /// <summary>

        /// 批量删除秘书公司业务表数据

        /// </summary>

        /// <param name="ids"></param>

        /// <returns></returns>

        public ActionResult DeleteAll(string ids)

        {

            JsonResult json = new JsonResult();

            json.Data = false;

            ids = ids.Substring(0, ids.Length - 1);

            string[] id = ids.Split(',');

            for (int i = 0; i < id.Length; i++)

            {

                // 调用删除方法

                SecretaryCreater.BusinessManager.DelBusinessIntroduceByID(Guid.Parse(id[i]));

                json.Data = true;

            }

            return Json(json.Data, JsonRequestBehavior.AllowGet);

        }

 

 

 

 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: