Ich versuche, ein Bearbeitungsformular für IdentityRole zu machen. Wenn die Seite geladen wird, erhalte ich normalerweise das Modell mit der ID "09e43076-c333-4145-bccb-8bc7f9db470e", aber wenn die Ansicht erstellt wird, sehe ich, dass @ Html.HiddenFor (m => m.Id) erhält einen alten Namen statt Id (siehe Screenshots in den Links unten). Warum passiert es? Vielen Dank!Warum IdentityRole-ID von alten Namen in Sicht überschrieben wird
GET: Edit
[HttpGet]
public ActionResult Edit(string id)
{
_context = new ApplicationDbContext();
if (User.Identity.IsAuthenticated)
{
if (!isAdminUser())
{
return RedirectToAction("Login", "Account");
}
}
else
{
return RedirectToAction("Login", "Account");
}
var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(new ApplicationDbContext()));
var role = roleManager.FindByName(id);
return View(role);
}
Ausblick: Bearbeiten
@model Microsoft.AspNet.Identity.EntityFramework.IdentityRole
@{
ViewBag.Title = "Edit Role";
}
<h2>Edit User Role:</h2>
@section RolesCSS {
<link href="@Url.Content("~/Views/Role/style/style.css")" rel="stylesheet"/>
<div class="form-group">
@using (Html.BeginForm("Edit", "Role", FormMethod.Post, new { @class = "AddRoleForm" }))
{
@Html.HiddenFor(m => m.Id)
@Html.HiddenFor(m => m.Users)
<div class="Label">
<p>Edit New User Role Name:</p>
</div>
<div class="FormControl">
@Html.EditorFor(m => m.Name, new {htmlAttributes = new {@class = "form-control"}})
</div>
<div class="FormControl">
<input class="btn btn-default" type="submit" value="Edit Role"/>
</div>
}
</div>
}
screenshot of values received as model in the view
screenshot of the source of the rendered html