How to modify user Group Operation in MVC4 production website
This article introduces how to modify the user group operation in the MVC4 production website, the content is very detailed, interested friends can refer to, hope to be helpful to you.
I. users
II. User groups
2.1 browse user groups
2.2 add user groups
2.3 modify user groups
First open [UserGroupController] and modify [Edit (int Id)] Action
/ / modify user group / user group Id / [AdminAuthorize] public ActionResult Edit (int Id) {userGroupRsy = new UserGroupRepository (); var _ userGroup = userGroupRsy.Find (Id); return View (_ userGroup);}
Right-click to enhance the type 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";} list on the left
Modify the user group data @ using (Html.BeginForm ("Eidt") "UserGroup") {@ Html.ValidationSummary (true) user group data @ Html.HiddenFor (model = > model.UserGroupId) @ Html.LabelFor (model = > model.Type) @ Html.DisplayTextFor (model = > model.Type) @ Html.LabelFor (model = > model.Name) @ Html.EditorFor (model = > model.Name) @ Html.ValidationMessageFor (model = > model.Name) @ Html.LabelFor (model = > model.Description) @ Html.EditorFor (model = > model.Description) @ Html.ValidationMessageFor (model = > model.Description)} @ section Scripts {@ Scripts.Render ("~ / bundles/jqueryval")}
Modify processing 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 other administrators", Solution = Server.UrlEncode ("return user group list")}; 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 = "successfully modified user group information", DwellTime = 3, NavigationName = "user group list", NavigationUrl = Url.Action ("List", "UserGroup")}; return RedirectToAction ("ManageNotice", "Prompt", _ n) } else {Error _ e = new Error {Title = "failed to update data", Details = "the modified information while modifying user group information could not be saved to the database." , Cause = Server.UrlEncode ("you have not changed the user group information. Database unknown error.") , Solution = Server.UrlEncode ("return to the list of user groups to modify user groups again")}; return RedirectToAction ("ManageError", "Prompt", _ e);}}
Open it in the browser and have a look.
Point Sav
Code packing address: http://xiazai.jb51.net/201608/yuanma/Ninesky(jb51.net).rar
On the MVC4 production site on how to modify the user group operation to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.