demo:
简单删除:
public ActionResult deleteDraft()
{
try
{
Guid ID = Guid.Parse(Request["ID"]);
OFDB ofdb = new OFDB();
OF_Draft draft = ofdb.draft.Find(ID);
ofdb.draft.Remove(draft);
ofdb.SaveChanges();
}
catch
{
return Content("error");
}
return Content("success");
}
批量删除:
view下:
function ReadList() {
$.ajax({
type: 'post',
url: '/OfficialFile/Outgoing/theDraft',
dataType: 'json',
data: { phase: '发文拟稿' },
success: function (data) {
var t = 2; //标识分页
$.each(data, function (index) {
$("#table_h tbody").append("<tr id=" + this.ID + "><td><input value=" + this.ID + " class='checkbox' type='checkbox'/></td><td>" + "<a οnclick='EditorDraft(\""+this.ID+"\")'>" + this.title + "</a>" + "</td><td>" + isnull(this.shopName) + "</td><td>" + this.kind + "</td><td>" + isnull(this.classification) + "</td><td>" + isnull(this.ponderance) + "</td><td><a οnclick='EditorDraft(\"" + this.ID + "\")'><span class='glyphicon glyphicon-pencil'></span>编辑</a> <a class='delete' name=" + this.ID + " οnclick='DeleteDraft(\"" + this.ID + "\")'><span class='glyphicon glyphicon-trash'></span>删除</a></td></tr>");
});
$("#table_h").dataTable({
oLanguage: {
sUrl: "/JS/DataTables-1.10.4/cn.txt"
}
});
}
});
}
全选:
$("#choice_all").click(function () {
$(".checkbox").prop("checked", "checked");
});
反选:
$("#choice_all_not").click(function () {
$(".checkbox").prop("checked", false);
});
$("#batch_delete").click(function () {
if (confirm("确定要删除所有已选择的发文吗?")) {
var DraftID = [];
$(".checkbox:checked").each(function (index) {
DraftID.push($(this).val()); //追加值到DraftID数组上
});
$.ajax({
url: '/OfficialFile/Outgoing/batchDeleteDraft',
type: 'post',
dataType: 'html',
data: { DraftID: DraftID },
success: function (data) {
if (data == "success") {
location.reload();
}
else {
alert(data);
}
}
});
}
});
控制器下:
public ActionResult batchDeleteDraft(Guid[] DraftID)
{
string result = string.Empty;
try
{
OFDB ofdb = new OFDB();
foreach (Guid j in DraftID)
{
var t = from i in ofdb.draft
where i.ID == j
select i;
ofdb.draft.RemoveRange(t);
}
ofdb.SaveChanges();
result = "success";
}
catch {
result = "error";
}
return Content(result);
}
批量拟稿:
view下:
<td colspan="8"><span id="choice_all" class="label label-primary">全选</span><span id="choice_all_not" style="margin-left: 10px;" class="label label-warning">反选</span><span id="complete_Nuclear" style="margin-left: 10px;" class="label label-success">完成核稿</span></td>
$("#choice_all").click(function () {
$(".checkbox").prop("checked","checked");
});
$("#choice_all_not").click(function () {
$(".checkbox").prop("checked",false);
});
//批量核稿
$("#complete_Nuclear").click(function () {
if (confirm("批量核稿?"))
{
var ID = [];
$(".checkbox:checked").each(function (index) {
ID.push($(this).val());
});
$.ajax({
url: '/OfficialFile/Outgoing/batchNuclear',
type: 'post',
dataType: 'html',
data: { ID: ID },
success: function (data) {
if (data == "success") {
location.reload();
}
else {
alert("批量核稿失败!");
}
}
});
}
});
控制器下:
public ActionResult batchNuclear(Guid[] ID)
{
string result = string.Empty;
try
{
OFDB ofdb = new OFDB();
for (int i = 0; i < ID.Length; i++)
{
OF_Draft draft = ofdb.draft.Find(ID[i]);
draft.phase = "套红盖章";
draft.state = "盖章中";
}
ofdb.SaveChanges();
result = "success";
}
catch {
result = "error";
}
return Content(result);
}