MVC4 Making Web Tutorials Chapter III Modify user group Operations 3.3_ practical Skills

Source: Internet
Author: User
Tags urlencode

First, users
Second, the user group

2.1 Browse User Groups
2.2 Adding user groups
2.3 Modifying user groups
First Open "Usergroupcontroller" and modify the [Edit (int Id)] Action

<summary>
 ///Modify 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 the enhanced type view and modify the view code (similar to the Add user group)

@model Ninesky.Models.UserGroup @{viewbag.title = "Modify User group";
Layout = "~/views/layout/_manage.cshtml";
<div class= "Left" > <div class= "Top" ></div> left-hand list </div> <div class= "Split" ></div> <div class= "Workspace" > <div class= "Inside" > <div class= "Notebar" >  Modify user Group Data </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> <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=" save "/> </div> </li> </ul> </fieldset> } </div> </div> <div class= "clear" ></div> @section Scripts {@Scripts. Render ("~/bundles/jquery
 Val ")}

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 = "errors occurred while modifying the user, the modified user group does not exist." ", cause =" The user group has been deleted by another administrator ", Solution = Server.URLEncode (" <li> return <a href= ' "+ url.action (" List "," usergroup ") +" ' &
 gt; 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 = "Successfully modified user group information", Dwelltime = 3, n
 Avigationname = "user group list", Navigationurl = url.action ("list", "UserGroup")};
 Return redirecttoaction ("Managenotice", "Prompt", _n); else {Error _e = new Error {Title = ' update data failed ', details = ' modified information when modifying user group information failed to be saved to the database. ", cause = Server.URLEncode (" <li> you did not change the user group information. </li><li> database is notKnow the wrong. </li> "), Solution = Server.URLEncode (" <li> return <a href= ' "+ url.action (" list "," usergroup ") +" ' > User group list </a></li><li> re-<a href= ' "+ url.action (" Edit "," UserGroup ", new {id = usergroup.usergroupid}) +" ' &
 gt; Modify user group </a></li> ")};
 Return redirecttoaction ("Manageerror", "Prompt", _e);
 }
 }

Browser Open Look

Point Save

Code Packaging Address: Http://xiazai.jb51.net/201608/yuanma/Ninesky (jb51.net). rar

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.