我有以下POST
方法来保存编辑用户详细信息:
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Edit_User(EditUserViewModel editUser, HttpPostedFileBase upload)
{
var store = new UserStore<ApplicationUser>(new DBEntities());
try
{
if (ModelState.IsValid)
{
var user = await UserManager.FindByIdAsync(editUser.Id);
if (user == null)
{
return HttpNotFound();
}
user.UserName = editUser.UserName;
user.Email = editUser.Email;
...
// update the user information
await UserManager.UpdateAsync(user);
var ctx = store.Context;
ctx.SaveChanges();
return RedirectToAction("Method", "Controller");
}
}
catch (Exception ex)
{
return View(editUser);
}
return View(editUser);
}
但是,一旦它在AspNetUser表中保存数据,我就没有收到任何错误,它会跳转到捕获异常。
如何正确保存此编辑用户详细信息?
答案 0 :(得分:0)
您是否使用以下方法更改了密钥: http://www.asp.net/identity/overview/extensibility/change-primary-key-for-users-in-aspnet-identity
包含以下步骤。你需要确保你得到每一个更正。
Change the type of the key in the Identity user class Add customized Identity classes that use the key type Change the context class and user manager to use the key type Change start-up configuration to use the key type For MVC with Update 2, change the AccountController to pass the key type For MVC with Update 3, change the AccountController and ManageController to pass the key type