oa_mvc_easyui_删除(6)
1.删除列,添加a标签,绑定参数
<a href="javascript:void(0)" class="delete" ids="@newlist.Id">删除</a>
2.绑定单击事件,删除提示,异步请求,回调函数对返回数据处理,表格中移除该元素(回调ok,数据库已删除,表格中还有,移除就行!)
//用于删除新闻的方法 function deleteInfo(id, control) { //提示信息 $.messager.confirm('提示', '确定要删除这条记录', function (r) { if (r) {//该条件成立表示删除该记录 //发送异步请求 $.post("/NewList/DeleteInfo", { "id": id }, function (data) { if (data == "ok") { //表格中删除该元素 $(control).parent().parent().remove(); $.messager.alert("提示", "删除成功", "info"); } else { $.messager.alert("提示", "删除失败", "info"); } }); } }); }
//绑定单击事件,用于删除 $(".delete").click(function () { deleteInfo($(this).attr("ids"),$(this)); })
3.数据层,业务层,视图中的方法
数据层:
/// <summary> /// 根据id删除一条数据 /// </summary> /// <param name="id"></param> /// <returns></returns> public int DeleteInfo(int id) { string sql = " delete from T_News where id =@id "; SqlParameter[] pars ={ new SqlParameter("@id",SqlDbType.Int) }; pars[0].Value = id; return DAL.SqlHelper.ExcuteSQLReturnInt(sql, CommandType.Text, pars); }
业务层:
/// <summary> /// 删除一条记录 /// </summary> /// <param name="id"></param> /// <returns></returns> public int DeleteInfo(int id) { return NewListInfo.DeleteInfo(id); }
视图:
/// <summary> /// 删除一条记录 /// </summary> /// <returns></returns> public ActionResult DeleteInfo() { int id = int.Parse(Request["id"]); int count = NewListInfo.DeleteInfo(id); if(count>0) { return Content("ok"); } else { return Content("no"); } }
You are never too old to set another goal or to dream a new dream!!!