JS多选删除,提交到后台MVC的action操作
2013-08-24 11:29
288 查看
--------------------------JS分割线------------------------------------------------
<script type="text/javascript">
// 提交到后台操作删除
function OnDelete() {
var ids = "";
$("input:checked").each(function () {
ids = ids + $(this).val() + ",";
});
if (ids.length > 0) {
if (confirm("确定删除吗?")) {
var url = "/Set_Business/DeleteAll?ids=" + ids;
$.getJSON(url, function (data) {
if (data) {
window.location.reload();
alert("删除成功!");
}
else {
alert("操作发生异常,删除成功!");
}
})
}
} else {
alert("请选择数据!");
}
}
// 标题行的checkbox, name为checkAll,数据行的的checkbox,name为selectFlag
$(function () {
//选中全部
$("#checkAll").click(function () {
if (this.checked) {
$("input[name='selectFlag']:checkbox").each(function () { //遍历所有的name为selectFlag的 checkbox
$(this).attr("checked", true);
})
}
else if (!this.checked) {
$("input[name='selectFlag']:checkbox").each(function () { //遍历所有的name为selectFlag的 checkbox
$(this).attr("checked", false);
})
}
})
//取消全选
// $("#delCheckAll").click(function () {
// if (this.checked) {
// $("input[name='selectFlag']:checkbox").each(function () { //遍历所有的name为selectFlag的 checkbox
// $(this).attr("checked", false);
// })
// }
// })
});
--------------------------有数据绑定的html分割线------------------------------------------------
<div class="top-btn">
<a href="/Set_Business/BusinessDel" onclick="OnDelete()">删除</a>
</div>
<table cellspacing="0" cellpadding="0" class="tb-entList">
<tr>
<th style="width: 24px;"><input class="check-box" name="checkAll" id="checkAll" type="checkbox" value="true"/></th>
<th style="width: 70px;">业务标题</th>
<th style="width: 70px;">创建人</th>
<th style="width: 80px;">创建时间</th>
</tr>
@if (businessList != null && businessList.Count > 0)
{
foreach (var item in businessList)
{
<tr>
<td><input class="check-box" type="checkbox" name="selectFlag" value="@item.BusinessID" /></td>
<td>@item.BusinessTitle</td>
<td>@item.CreateUserName</td>
</tr>
}
}
else
{
<tr><td colspan="11"> 暂无数据</td></tr>
}
</table>
--------------------------后台处理分割线------------------------------------------------
/// <summary>
/// 批量删除秘书公司业务表数据
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
public ActionResult DeleteAll(string ids)
{
JsonResult json = new JsonResult();
json.Data = false;
ids = ids.Substring(0, ids.Length - 1);
string[] id = ids.Split(',');
for (int i = 0; i < id.Length; i++)
{
// 调用删除方法
SecretaryCreater.BusinessManager.DelBusinessIntroduceByID(Guid.Parse(id[i]));
json.Data = true;
}
return Json(json.Data, JsonRequestBehavior.AllowGet);
}
<script type="text/javascript">
// 提交到后台操作删除
function OnDelete() {
var ids = "";
$("input:checked").each(function () {
ids = ids + $(this).val() + ",";
});
if (ids.length > 0) {
if (confirm("确定删除吗?")) {
var url = "/Set_Business/DeleteAll?ids=" + ids;
$.getJSON(url, function (data) {
if (data) {
window.location.reload();
alert("删除成功!");
}
else {
alert("操作发生异常,删除成功!");
}
})
}
} else {
alert("请选择数据!");
}
}
// 标题行的checkbox, name为checkAll,数据行的的checkbox,name为selectFlag
$(function () {
//选中全部
$("#checkAll").click(function () {
if (this.checked) {
$("input[name='selectFlag']:checkbox").each(function () { //遍历所有的name为selectFlag的 checkbox
$(this).attr("checked", true);
})
}
else if (!this.checked) {
$("input[name='selectFlag']:checkbox").each(function () { //遍历所有的name为selectFlag的 checkbox
$(this).attr("checked", false);
})
}
})
//取消全选
// $("#delCheckAll").click(function () {
// if (this.checked) {
// $("input[name='selectFlag']:checkbox").each(function () { //遍历所有的name为selectFlag的 checkbox
// $(this).attr("checked", false);
// })
// }
// })
});
--------------------------有数据绑定的html分割线------------------------------------------------
<div class="top-btn">
<a href="/Set_Business/BusinessDel" onclick="OnDelete()">删除</a>
</div>
<table cellspacing="0" cellpadding="0" class="tb-entList">
<tr>
<th style="width: 24px;"><input class="check-box" name="checkAll" id="checkAll" type="checkbox" value="true"/></th>
<th style="width: 70px;">业务标题</th>
<th style="width: 70px;">创建人</th>
<th style="width: 80px;">创建时间</th>
</tr>
@if (businessList != null && businessList.Count > 0)
{
foreach (var item in businessList)
{
<tr>
<td><input class="check-box" type="checkbox" name="selectFlag" value="@item.BusinessID" /></td>
<td>@item.BusinessTitle</td>
<td>@item.CreateUserName</td>
</tr>
}
}
else
{
<tr><td colspan="11"> 暂无数据</td></tr>
}
</table>
--------------------------后台处理分割线------------------------------------------------
/// <summary>
/// 批量删除秘书公司业务表数据
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
public ActionResult DeleteAll(string ids)
{
JsonResult json = new JsonResult();
json.Data = false;
ids = ids.Substring(0, ids.Length - 1);
string[] id = ids.Split(',');
for (int i = 0; i < id.Length; i++)
{
// 调用删除方法
SecretaryCreater.BusinessManager.DelBusinessIntroduceByID(Guid.Parse(id[i]));
json.Data = true;
}
return Json(json.Data, JsonRequestBehavior.AllowGet);
}
相关文章推荐
- js操作cookie,asp.net后台删除cookie
- js往后台Action提交
- SpringMvc+POI 处理Excel的导入操作(一般form提交和jquery.form.js提交)
- js 页面按钮提交后 创建显示loading div 操作完成后 再隐藏或删除 进度div
- js操作cookie以实验array数据在ajax向action交换数据时得到保存,用于实现批量删除的工作(未完)
- js里对options的增加删除提交操作
- form提交action之前用js操作
- JS操作select相关方法:新增 修改 删除 选中 清空 判断存在
- JS操作select相关方法:新增 修改 删除 选中 清空 判断存在 等
- JS操作select下拉框动态变动(创建/删除/获取)
- 一步一步使用Ext JS MVC与Asp.Net MVC 3开发简单的CMS后台管理系统之登录窗口调试
- js 输入框增加删除操作
- 一步一步使用Ext JS MVC与Asp.Net MVC 3开发简单的CMS后台管理系统之预告篇
- ajax 参数data问题 data中的 参数名 参数值为string 提交到后台后,会自动转换参数名相同的 类型 和 js字符串拼接
- JS数组操作(数组增加、删除、翻转、转字符串、取索引、截取(切片)slice、剪接splice、数组合并)
- js保存,获取,删除cookie的操作
- jquery.form.js后台提交成功,但没触发回调函数
- MVC路由规则以及前后台获取Action、Controller、ID名方法
- js操作节点(添加、删除、更改属性)
- Laravel 中使用 Vue.js 实现基于 Ajax 的表单提交错误验证操作