私はIdentityRoleの編集フォームを作成しようとしています。ページがロードされると、私は通常、この "09e43076-c333-4145-bccb-8bc7f9db470e"のようなIdを持つモデルを受け取りますが、ビューが作成されると、@ Html.HiddenFor(m => m.Id) Idの代わりに古い名前の値を取得します(下のリンクのスクリーンショットを参照)。なぜそれが起こっているのですか?ありがとう!IdentityRole IDが表示で古い名前で上書きされる理由
GET:編集
[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);
}
ビュー:編集
@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