1. 程式人生 > >MVC4.0實現批量刪除

MVC4.0實現批量刪除

onf ont app http ack link add details post

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();

}

}


來自:http://www.cnblogs.com/sky-net/p/4415697.html

MVC4.0實現批量刪除