First, users
Second, the user group
2.1 Browse User Groups
2.2 Adding user groups
Modify [Add]action
<summary>
///Add user group
///</summary>
///<returns></returns>
[ Adminauthorize] public
actionresult Add ()
{
viewdata.add ("Type", typeselectlist);
return View ();
}
Add Enhanced Type View
After the completion of 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> left-hand list </div> <div class= "Split" ></div> <div class= "Workspace" > <div class= "Inside" > <div class= "Notebar" > Add user group </div> @using (Html.BeginForm ()) {@Html. ValidationSummary (tru E <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> <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 (mod El => 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/jqueryval")}
Modify user group Add Processing action [Add (UserGroup usergroup)]action, completed code
[HttpPost]
[Adminauthorize]
Public ActionResult Add (usergroup usergroup)
{
usergrouprsy = new Usergrouprepository ();
if (Usergrouprsy.add (usergroup))
{
Notice _n = new Notice {Title = "Add user group succeeded", 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 = "Add user group failed", Details = "Failed to save to database when adding user group", cause = "System error", Solution = Server . UrlEncode ("<li> return <a href= '" + url.action ("Add", "usergroup") + "' > Add User </a> page, enter correct information and then restart </li ><li> Contact webmaster </li> ")};
Return redirecttoaction ("Manageerror", "Prompt", _e);
}
View in the browser
Input data test, you can add data.
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.