国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

MVC4制作網站教程第三章 刪除用戶組操作3.4

2024-07-10 13:31:17
字體:
來源:轉載
供稿:網友

一、用戶
二、用戶組

2.1瀏覽用戶組 
2.2添加用戶組 
2.3修改用戶組 
2.4刪除用戶組 

刪除用戶組相對簡單些,不用單獨的頁面,直接在瀏覽頁面點擊刪除時,彈出確認刪除對話框,點擊確認,用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("你確定要刪除【" + name + "】嗎?")) { $.post("@Url.Content("~/UserGroup/Delete")", {Id:id}, function (data) { if (data) { alert("刪除【" + name + "】成功!"); location.reload(); } }); } } 

完成后整個List.cshtml的代碼如下: 

@model IEnumerable<Ninesky.Models.UserGroup>@{ ViewBag.Title = "用戶組列表"; Layout = "~/Views/Layout/_Manage.cshtml";}<div class="left"> <div class="top"></div> 左側列表</div><div class="split"></div><div class="workspace"> <div class="inside"> <div class="notebar"> <img </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("你確定要刪除【" + name + "】嗎?")) { $.post("@Url.Content("~/UserGroup/Delete")", {Id:id}, function (data) { if (data) { alert("刪除【" + name + "】成功!"); location.reload(); } }); } }</script> 

到此打完收工! 

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VeVb武林網。


注:相關教程知識閱讀請移步到ASP.NET教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 浏阳市| 溆浦县| 平乐县| 眉山市| 黔西县| 合阳县| 龙岩市| 宁国市| 红安县| 新昌县| 天津市| 当涂县| 桐乡市| 辽阳县| 黎平县| 武陟县| 依兰县| 海淀区| 天水市| 铜川市| 手游| 临沭县| 文水县| 荆门市| 南岸区| 广灵县| 永兴县| 江阴市| 西林县| 海口市| 比如县| 云龙县| 湛江市| 盘山县| 驻马店市| 哈尔滨市| 广宁县| 靖江市| 甘南县| 礼泉县| 济阳县|