Get the App
SLTechnology News&Howtos  ›  Development  › 

How to add user group operation in MVC4 production website

Shulou Source: shulou.com Published: 2022-06-03 12:55:53 09月27日 Update

MVC4 production website how to develop user group operation, many novices are not very clear about this, in order to help you solve this problem, the following small series will explain in detail for everyone, there are people who need this can learn, I hope you can harvest.

I. Users

II. User Groups

2.1 to post within this

2.2 add user group

Edit [Add]Action

/// ///add user group /// /// [AdminAuthorize] public ActionResult Add() { ViewData.Add("Type", TypeSelectList); return View(); }

Add Strongly Typed Views

After completion, the code is as follows:

@model Ninesky.Models.UserGroup@{ ViewBag.Title = "Add User Group"; Layout = "~/Views/Layout/_Manage.cshtml";} Left List

add user group @using (Html.BeginForm()) { @Html.ValidationSummary(true) user group data @Html.HiddenFor(model => model.UserGroupId) @Html.LabelFor(model => model.Type) @Html.DropDownList("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 User Group Add Action [Add(UserGroup userGroup)]Action, code after completion

[HttpPost] [AdminAuthorize] public ActionResult Add(UserGroup userGroup) { userGroupRsy = new UserGroupRepository(); if (userGroupRsy.Add(userGroup)) { Notice _n = new Notice { Title = "Add User Group 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("Return to add user page, enter correct information and try again to contact website administrator") }; return RedirectToAction("ManageError", "Prompt", _e); } }

Check it in your browser.

Enter information to test it, you can add information.

Did reading the above help you? If you still want to have further understanding of related knowledge or read more related articles, please pay attention to the industry information channel, thank you for your support.

Tags: Users user groups materials websites success help browsing input creating websites production clarity code information content actions descendants this data databases articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Huawei macOS Shulou Technology Shulou Information