jquery 批量删除

$("#btn_delete").click(function () {
var row = $("#tb_hero").bootstrapTable('getSelections');
var arrId = [];
var ids = {};
for (var i = 0; i < row.length; i++) {
ids = row[i].Id;
arrId.push(ids);
}                                 //数组
console.log(arrId);
$.ajax({
url: "/Backstage/Delete",
type: "post",
data: { ID: arrId.join(',') },
success: function (result) {
console.log(result);
alert(result);
$("#tb_hero").bootstrapTable('refresh');
}
});
});

 

后台:

 private DataEntities DE = new DataEntities();  //上下文

public ActionResult Delete(string ID)
{
foreach (string id in ID.Split(','))  
{
int? Id=Convert.ToInt32(id);
var model = DE.英雄.Where(m => m.Id == Id).SingleOrDefault();
if (model != null)
{
DE.Entry<英雄>(model).State = EntityState.Deleted;
DE.SaveChanges();
}
}
return Json("删除成功", JsonRequestBehavior.AllowGet);
}

posted @ 2018-11-30 11:06  提笔  阅读(1034)  评论(0编辑  收藏  举报