MVC4制作網(wǎng)站教程第三章 刪除用戶組操作3.4
一、用戶
二、用戶組
2.1瀏覽用戶組
2.2添加用戶組
2.3修改用戶組
2.4刪除用戶組
刪除用戶組相對(duì)簡(jiǎn)單些,不用單獨(dú)的頁(yè)面,直接在瀏覽頁(yè)面點(diǎn)擊刪除時(shí),彈出確認(rèn)刪除對(duì)話框,點(diǎn)擊確認(rèn),用jquery post刪除。
打開【UserGroupController】,刪掉public ActionResult Delele(int GroupId) { return View(); }
修改刪除處理Action[Delete(int Id)],修改后的代碼
/// <summary> /// 刪除用戶組 /// </summary> /// <param name="Id">用戶組Id</param> /// <returns></returns> [HttpPost] [AdminAuthorize] public JsonResult Delete(int Id) { userGroupRsy = new UserGroupRepository(); if (userGroupRsy.Delete(Id)) return Json(true); else return Json(false); }
這里返回類型為JsonResult目的方便使用jquery 的post方式刪除。
打開List.cshtml,將@Html.ActionLink("刪除", "Delete", new { id = item.UserGroupId }) 改為<a href="javascript:void(0)" onclick="Delete(@item.UserGroupId,'@item.Name')" >刪除</a>
在文件底部添加腳本
function Delete(id,name) { if (confirm("你確定要?jiǎng)h除【" + name + "】嗎?")) { $.post("@Url.Content("~/UserGroup/Delete")", {Id:id}, function (data) { if (data) { alert("刪除【" + name + "】成功!"); location.reload(); } }); } }
完成后整個(gè)List.cshtml的代碼如下:
@model IEnumerable<Ninesky.Models.UserGroup> @{ ViewBag.Title = "用戶組列表"; Layout = "~/Views/Layout/_Manage.cshtml"; } <div class="left"> <div class="top"></div> 左側(cè)列表 </div> <div class="split"></div> <div class="workspace"> <div class="inside"> <div class="notebar"> <img alt="" src="~/Skins/Default/Manage/Images/UserGroup.gif" />用戶組列表 </div> <div class="buttonbar">@Html.ActionLink("添加用戶組", "Add", "UserGroup") 用戶組類型: @Html.DropDownList("GroupTypeList") </div> <table> <tr> <th> @Html.DisplayNameFor(model => model.Name) </th> <th> @Html.DisplayNameFor(model => model.Type) </th> <th> @Html.DisplayNameFor(model => model.Description) </th> <th></th> </tr> @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.Name) </td> <td> @Html.DisplayFor(modelItem => item.Type) </td> <td> @Html.DisplayFor(modelItem => item.Description) </td> <td> @Html.ActionLink("修改", "Edit", new { id = item.UserGroupId }) | <a href="javascript:void(0)" onclick="Delete(@item.UserGroupId,'@item.Name')" >刪除</a> </td> </tr> } </table> </div> </div> <div class="clear"></div> <script type="text/javascript"> $("#GroupTypeList").change(function () { window.location.href = "/UserGroup/List/" + $(this).children("option:selected").val(); }) function Delete(id,name) { if (confirm("你確定要?jiǎng)h除【" + name + "】嗎?")) { $.post("@Url.Content("~/UserGroup/Delete")", {Id:id}, function (data) { if (data) { alert("刪除【" + name + "】成功!"); location.reload(); } }); } } </script>
到此打完收工!
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- ASP.NET MVC5網(wǎng)站開發(fā)管理列表、回復(fù)及刪除(十三)
- ASP.NET MVC5網(wǎng)站開發(fā)我的咨詢列表及添加咨詢(十二)
- ASP.NET MVC5網(wǎng)站開發(fā)修改及刪除文章(十)
- ASP.NET MVC5網(wǎng)站開發(fā)添加文章(八)
- ASP.NET MVC5網(wǎng)站開發(fā)文章管理架構(gòu)(七)
- ASP.NET MVC5網(wǎng)站開發(fā)用戶修改資料和密碼(六)
- ASP.NET?MVC5網(wǎng)站開發(fā)用戶登錄、注銷(五)
- ASP.NET?MVC5網(wǎng)站開發(fā)用戶注冊(cè)(四)
- ASP.NET MVC5網(wǎng)站開發(fā)項(xiàng)目框架(二)
- ASP.NET MVC5網(wǎng)站開發(fā)概述(一)
相關(guān)文章
ASP.NET?MVC使用Quartz.NET執(zhí)行定時(shí)任務(wù)
這篇文章介紹了ASP.NET?MVC使用Quartz.NET執(zhí)行定時(shí)任務(wù)的方法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-09-09.net/c# memcached緩存獲取所有緩存鍵的方法步驟
這篇文章主要介紹了.net/c# memcached緩存獲取所有緩存鍵的方法步驟,大家參考使用吧2013-12-12解析利用wsdl.exe生成webservice代理類的詳解
本篇文章是對(duì)利用wsdl.exe生成webservice代理類進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05MVC4制作網(wǎng)站教程第二章 用戶注冊(cè)2.1
這篇文章主要為大家詳細(xì)介紹了MVC4制作網(wǎng)站教程,用戶注冊(cè)功能的實(shí)現(xiàn)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-08-08使用Entity Framework(4.3.1版本)遇到的問題整理
在這里記錄一下之前使用Entity Framework(4.3.1版本)遇到的問題:更新沒有設(shè)置主鍵的表、更改Code-First的默認(rèn)連接、檢測(cè)字符串截?cái)噱e(cuò)誤,需要的朋友可以參考下2012-12-12Asp.net mvc實(shí)時(shí)生成縮率圖到硬盤
這篇文章主要介紹了Asp.net mvc實(shí)時(shí)生成縮率圖到硬盤的相關(guān)資料,需要的朋友可以參考下2016-05-05Asp.net開發(fā)之webform圖片水印和圖片驗(yàn)證碼的實(shí)現(xiàn)方法
這篇文章主要介紹了Asp.net開發(fā)之webform圖片水印和圖片驗(yàn)證碼的實(shí)現(xiàn)方法,實(shí)現(xiàn)思路分為前后臺(tái)代碼和效果展示,非常不錯(cuò)具有參考借鑒價(jià)值,需要的朋友可以參考下2016-10-10Asp.Net Core輕松學(xué)之利用日志監(jiān)視進(jìn)行服務(wù)遙測(cè)詳解
這篇文章主要給大家介紹了關(guān)于Asp.Net Core輕松學(xué)之利用日志監(jiān)視進(jìn)行服務(wù)遙測(cè)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起看看吧2018-12-12asp.net實(shí)現(xiàn)刪除DataGrid的記錄時(shí)彈出提示信息
這篇文章主要介紹了asp.net實(shí)現(xiàn)刪除DataGrid的記錄時(shí)彈出提示信息,非常實(shí)用的功能,需要的朋友可以參考下2014-08-08