//删除的时候执行的代码
function deleteEvent() {
//第一步拿到easyui里面选中项的id
var selectedRows = $('#tt').datagrid("getSelections");
//如果没有选中
if (selectedRows.length <= 0) {
$.messager.alert("错误提醒", "请选中删除的数据", "error");
return;
}
var ids = "";
//把数据删除
for (var key in selectedRows) {
ids = ids + selectedRows[key].ID + ",";
}
//ids: 1,2,3,
ids = ids.substr(0, ids.length - 1);
console.log(ids);
$.post("/DepartmentInfo/Delete", { ids: ids }, function (data) {
if (data == "ok") {
//刷新表之后再初始化一下
selectedRows = $('#tt').datagrid("getSelections");
//刷新表
initTable();
} else {
$.messager.alert("提醒消息", "删除失败", "error");
}
});
}
删除时执行的后台代码
public ActionResult Delete(string ids)
{
if (string.IsNullOrEmpty(ids))
{
return Content("请选中要删除的数据!");
}
//正常处理
string[] strIds= ids.Split(',');
List<int> idList = new List<int>();
//批量删除
foreach (var item in strIds)
{
idList.Add(int.Parse(item));
}
UserInfoServer.DeleteList(idList);
return Content("ok");
}