zoukankan      html  css  js  c++  java
  • MVC4.0实现批量删除

    HTML:

    @using(Html.BeginForm("Delete","Home")){
       <div>
           <input type="submit" value="删除" class="delete" onclick="return confirm('确定要删除吗?')"/>
       </div>
        <table>
            <tr>
                <th>@Html.CheckBox("chackall")</th>
                <th>标题</th>
                <th>操作</th>
            </tr>
            <tr>
                <td>@Html.CheckBox("checkid",new{ value="1"})</td>
                <td>数据1</td>
                <td>@Html.ActionLink("详细","Details",new{ id="1"})</td>
            </tr>
            <tr>
                <td>@Html.CheckBox("checkid",new{ value="2"})</td>
                <td>数据2</td>
                <td>@Html.ActionLink("详细","Details",new{ id="2"})</td>
            </tr>
            <tr>
                <td>@Html.CheckBox("checkid",new{ value="3"})</td>
                <td>数据3</td>
                <td>@Html.ActionLink("详细","Details",new{ id="3"})</td>
            </tr>
            <tr>
                <td>@Html.CheckBox("checkid",new{ value="4"})</td>
                <td>数据4</td>
                <td>@Html.ActionLink("详细","Details",new{ id="4"})</td>
            </tr>
            <tr>
                <td>@Html.CheckBox("checkid",new{ value="5"})</td>
                <td>数据5</td>
                <td>@Html.ActionLink("详细","Details",new{ id="5"})</td>
            </tr>
        </table>
    }

    Action:

            [HttpPost]
            public ActionResult Delete(List<string> checkid)
            {
                ApplicationContext db=new ApplicationContext();
                try
                {
                    // TODO: Add delete logic here
                    db.RemoveAll(m => checkid.Contains(m.id));
                    db.SaveChanges(); 
    
                    return RedirectToAction("Index");
                }
                catch
                {
                    return View();
                }
            }
  • 相关阅读:
    Markdown基本必学语法
    Javascript检测值
    JS中的函数传参
    解决windows下node-sass报错的问题
    scroll的应用
    css中常见几种float方式以及倒计时(刷新页面不清)
    jquery中append与appendTo方法区别
    如何利用sql注入进行爆库
    Smarty静态缓存
    我的DBDA类
  • 原文地址:https://www.cnblogs.com/sky-net/p/4415697.html
Copyright © 2011-2022 走看看