温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

MVC4制作网站中如何删除用户组操作

发布时间:2021-09-16 16:42:10 来源:亿速云 阅读:124 作者:柒染 栏目:开发技术

本篇文章给大家分享的是有关MVC4制作网站中如何删除用户组操作,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

一、用户
二、用户组

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 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("你确定要删除【" + name + "】吗?")) {
 $.post("@Url.Content("~/UserGroup/Delete")", {Id:id}, function (data) {
 if (data) {
 alert("删除【" + name + "】成功!");
 location.reload();
 }
 });
 }
 }
</script>

到此打完收工! 

以上就是MVC4制作网站中如何删除用户组操作,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI