一、用戶
二、用戶組
2.1浏覽用戶組
2.2添加用戶組
2.3修改用戶組
首先打開【UserGroupController】,修改[Edit(int Id)] Action
/// <summary> /// 修改用戶組 /// </summary> /// <param name="Id">用戶組Id</param> /// <returns></returns> [AdminAuthorize] public ActionResult Edit(int Id) { userGroupRsy = new UserGroupRepository(); var _userGroup = userGroupRsy.Find(Id); return View(_userGroup); }
右鍵添加強類型視圖,並修改視圖代碼(與添加用戶組類似)
@model 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> @using (Html.BeginForm("Eidt","UserGroup")) { @Html.ValidationSummary(true) <fieldset> <legend>用戶組資料</legend> @Html.HiddenFor(model => model.UserGroupId) <ul> <li> <div class="editor-label"> @Html.LabelFor(model => model.Type) </div> <div class="editor-field"> @Html.DisplayTextFor(model => model.Type) </div> </li> <li> <div class="editor-label"> @Html.LabelFor(model => model.Name) </div> <div class="editor-field"> @Html.EditorFor(model => model.Name) @Html.ValidationMessageFor(model => model.Name) </div> </li> <li> <div class="editor-label"> @Html.LabelFor(model => model.Description) </div> <div class="editor-field"> @Html.EditorFor(model => model.Description) @Html.ValidationMessageFor(model => model.Description) </div> </li> <li> <div class="editor-label"> </div> <div class="editor-field"> <input type="submit" value="保存" /> </div> </li> </ul> </fieldset> } </div> </div> <div class="clear"></div> @section Scripts { @Scripts.Render("~/bundles/jqueryval") }
修改處理Action[Eidt(UserGroup userGroup)]
[HttpPost] [AdminAuthorize] public ActionResult Eidt(UserGroup userGroup) { userGroupRsy = new UserGroupRepository(); var _userGroup = userGroupRsy.Find(userGroup.UserGroupId); if (_userGroup == null) { Error _e = new Error { Title = "用戶組不存在", Details = "修改用戶時發生錯誤,修改的用戶組不存在。", Cause = "該用戶組已被其他管理員刪除", Solution = Server.UrlEncode("<li>返回<a href='" + Url.Action("List", "UserGroup") + "'>用戶組列表</a></li>") }; return RedirectToAction("ManageError", "Prompt", _e); } _userGroup.Name = userGroup.Name; _userGroup.Description = userGroup.Description; if (userGroupRsy.Update(_userGroup)) { Notice _n = new Notice { Title = "修改成功", Details = "成功修改了用戶組信息", DwellTime = 3, NavigationName = "用戶組列表", NavigationUrl = Url.Action("List", "UserGroup") }; return RedirectToAction("ManageNotice", "Prompt", _n); } else { Error _e = new Error { Title = "更新數據失敗", Details = "修改用戶組信息時修改的信息未能保存到數據庫。", Cause = Server.UrlEncode("<li>您並未更改用戶組信息。</li><li>數據庫未知錯誤。</li>"), Solution = Server.UrlEncode("<li>返回<a href='" + Url.Action("List", "UserGroup") + "'>用戶組列表</a></li><li>重新<a href='" + Url.Action("Edit", "UserGroup", new { id = userGroup.UserGroupId }) + "'>修改用戶組</a></li>") }; return RedirectToAction("ManageError", "Prompt", _e); } }
浏覽器中打開看一下
點保存
代碼打包地址:http://xiazai.jb51.net/201608/yuanma/Ninesky(jb51.net).rar
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。