标签:ons index space src rect entity 一个 control color
因只有角色名能修改故继续使用创建角色的视图模型
using System.ComponentModel; using System.ComponentModel.DataAnnotations; namespace Shop.ViewModel { public class CreateEditRoleViewModel { [Required(ErrorMessage = "角色名不能为空")] [DisplayName("角色名")] public string Name { get; set; } } }
修改角色的方法
// GET: RoleController/Edit/5 public ActionResult Edit(int id) { return View(); } // POST: RoleController/Edit/5 [HttpPost] [ValidateAntiForgeryToken] public async Task<ActionResult> Edit(string id, CreateEditRoleViewModel input) { var role = await _roleManager.FindByIdAsync(id); if (role != null) { role.Name = input.Name; var result = await _roleManager.UpdateAsync(role); if (result.Succeeded) { return RedirectToAction("Index"); } foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } } return View(input); }
编辑角色视图
@model Shop.ViewModel.CreateEditRoleViewModel @*因只需要一个角色名,故直接使用了创建视图模型*@ @{ ViewData["Title"] = "Edit"; } <h1>Edit</h1> <h4>编辑角色</h4> <hr /> <div class="row"> <div class="col-md-4"> <form asp-action="Edit"> <div asp-validation-summary="ModelOnly" class="text-danger"></div> <div class="form-group"> <label asp-for="Name" class="control-label"></label> <input asp-for="Name" class="form-control" /> <span asp-validation-for="Name" class="text-danger"></span> </div> <div class="form-group"> <input type="submit" value="Save" class="btn btn-primary" /> </div> </form> </div> </div> @section Scripts { @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} }
编辑角色及报错展示
标签:ons index space src rect entity 一个 control color
原文地址:https://www.cnblogs.com/liessay/p/13212156.html