Chapter 3 modifying user group operations 3.3, mvc43.3

Source: Internet
Author: User

Chapter 3 modifying user group operations 3.3, mvc43.3

I. Users
Ii. User Group
 
2.1 browsing user groups
2.2 Add a user group
2.3 modify user groups
First open [UserGroupController] and modify [Edit (int Id)] Action

/// <Summary> /// modify the user group /// </summary> /// <param name = "Id"> User Group Id </param> /// <returns> </returns> [AdminAuthorize] public ActionResult Edit (int Id) {userGroupRsy = new UserGroupRepository (); var _ userGroup = userGroupRsy. find (Id); return View (_ userGroup );}

Right-click to add a strong view and modify the view code (similar to adding a user group)

@ Model Ninesky. Models. UserGroup @ {ViewBag. Title = "Modify user group"; Layout = "~ /Views/Layout/_ Manage. cshtml ";} <div class = "left"> <div class = "top"> </div> list on the left </div> <div class = "split"> </div> <div class = "workspace"> <div class = "inside"> <div class = "notebar">  modify user group information </div> @ using (Html. beginForm ("Eidt", "UserGroup") {@ Html. validationSummary (true) <fieldset> <legend> User Group Information </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> <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> <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 = "save"/> </div> </li> </ul> </fieldset >}</div> <div class = "clear"> </div> @ section Scripts {@ Scripts. render ("~ /Bundles/jqueryval ")}

Modify and process 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 = "User Group does not exist", Details = "An Error occurred while modifying the user. The modified User Group does not exist. ", Cause =" this user group has been deleted by another administrator ", Solution = Server. urlEncode ("<li> Returns <a href = '" + Url. action ("List", "UserGroup") + "'> User Group List </a> </li>")}; return RedirectToAction ("ManageError", "Prompt ", _ e);} _ userGroup. name = userGroup. name; _ userGroup. description = userGroup. description; if (userGroupRsy. update (_ userGroup) {Notice _ n = new Notice {Title = "modified successfully", Details = "modified User Group information", DwellTime = 3, NavigationN Ame = "User Group list", NavigationUrl = Url. action ("List", "UserGroup")}; return RedirectToAction ("ManageNotice", "Prompt", _ n );} else {Error _ e = new Error {Title = "failed to update data", Details = "failed to save the modified information to the database when modifying user group information. ", Cause = Server. UrlEncode (" <li> you have not changed the user group information. </Li> <li> unknown database error. </Li> "), Solution = Server. urlEncode ("<li> Returns <a href = '" + Url. action ("List", "UserGroup") + "'> User Group List </a> </li> <li> re-<a href ='" + Url. action ("Edit", "UserGroup", new {id = userGroup. userGroupId}) + "'> modify user group </a> </li>")}; return RedirectToAction ("ManageError", "Prompt", _ e );}}

Open it in the browser.

Click Save

Code package address: http://xiazai.jb51.net/201608/yuanma/Ninesky (jb51.netw..rar

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.