MVC4制作网站教程第三章 删除用户组操作3.4

2025-05-29 0 103

一、用户
二、用户组

2.1浏览用户组
2.2添加用户组
2.3修改用户组
2.4删除用户组

删除用户组相对简单些,不用单独的页面,直接在浏览页面点击删除时,弹出确认删除对话框,点击确认,用jquery post删除。

打开【UserGroupController】,删掉public ActionResult Delele(int GroupId) { return View(); }

修改删除处理Action[Delete(int Id)],修改后的代码

?

1

2

3

4

5

6

7

8

9

10

11

12

13
/// <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>

在文件底部添加脚本

?

1

2

3

4

5

6

7

8

9

10
function Delete(id,name) {

if (confirm("你确定要删除【" + name + "】吗?")) {

$.post("@Url.Content("~/UserGroup/Delete")", {Id:id}, function (data) {

if (data) {

alert("删除【" + name + "】成功!");

location.reload();

}

});

}

}

完成后整个List.cshtml的代码如下:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69
@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>

到此打完收工!

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持快网idc。

原文链接:http://www.cnblogs.com/mzwhj/archive/2012/11/15/2771014.html

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 MVC4制作网站教程第三章 删除用户组操作3.4 https://www.kuaiidc.com/100364.html

相关文章

发表评论
暂无评论