Chapter 3 Add User Group Operation 3.2, mvc43.2

Source: Internet
Author: User

Chapter 3 Add User Group Operation 3.2, mvc43.2

I. Users

Ii. User Group

2.1 browsing user groups

2.2 Add a user group

Modify [Add] Action

/// <Summary> /// Add User Group /// </summary> /// <returns> </returns> [AdminAuthorize] public ActionResult Add () {ViewData. add ("Type", TypeSelectList); return View ();}

Add a strong view

The Code is as follows:

@ Model Ninesky. Models. UserGroup @ {ViewBag. Title = "Add 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">  Add a user group </div> @ using (Html. beginForm () {@ 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. dropDownList ("Type") </div> </li> <div class = "editor-label"> @ Html. labelFor (model => mod El. 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> <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 the User Group to Add the processing Action [Add (UserGroup userGroup)] Action, the code after completion

[HttpPost] [AdminAuthorize] public ActionResult Add (UserGroup userGroup) {userGroupRsy = new UserGroupRepository (); if (userGroupRsy. add (userGroup) {Notice _ n = new Notice {Title = "User Group added successfully", Details = "you have successfully added [" + userGroup. name + "] user group! ", DwellTime = 5, NavigationName =" User Group list ", NavigationUrl = Url. action ("List", "UserGroup")}; return RedirectToAction ("ManageNotice", "Prompt", _ n );} else {Error _ e = new Error {Title = "failed to add user group", Details = "failed to save to database when adding user group", Cause = "system Error ", solution = Server. urlEncode ("<li> Returns <a href = '" + Url. action ("Add", "UserGroup") + "'> Add User </a> page, enter the correct information and try again </li> <li> contact the website administrator </li> ")}; return RedirectToAction (" ManageError "," Prompt ", _ e );}}

Check in the browser

Enter the required information to test. You can add the required information.

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.