I add 3 roles to database. "Admin"
,"Moderator"
and "User"
. I want simply rename
"Admin"
to "Administrator"
. I use this code, but its not correct work. Its return me error {"Database operation expected to affect 1 row(s) but actually affected 0 row(s). Data may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=527962 for information on understanding and handling optimistic concurrency exceptions."}
Edit.cshtml
@model Microsoft.AspNet.Identity.EntityFramework.IdentityRole
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.Id)
<div>
Role name
</div>
<p>
@Html.TextBoxFor(model => model.Name)
</p>
<input type="submit" value="Save" />
}
RoleController
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(IdentityRole role) //IdentityRole role
{
try
{
context.Entry(role).State = EntityState.Modified;
context.SaveChanges();
return RedirectToAction("Index");
}
catch (Exception ex)
{
return View();
}
}