我已经向ApplicationUser
类添加了定制字段
我还创建了一个表单,用户可以通过它输入/编辑字段。
但是,由于某些原因,我无法更新数据库中的字段。
[HttpPost]
[ActionName("Edit")]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Manage(EditProfileViewModel model)
{
if (ModelState.IsValid)
{
// Get the current application user
var user = User.Identity.GetApplicationUser();
// Update the details
user.Name = new Name { First = model.FirstName, Last = model.LastName, Nickname = model.NickName };
user.Birthday = model.Birthdate;
// This is the part that doesn't work
var result = await UserManager.UpdateAsync(user);
// However, it always succeeds inspite of not updating the database
if (!result.Succeeded)
{
AddErrors(result);
}
}
return RedirectToAction("Manage");
}
我的问题与MVC5 ApplicationUser custom properties类似,但似乎使用了旧版本的Identity,因为IdentityManager类似乎不存在。
有人能指导我如何更新数据库中的 User
信息吗?
更新:如果我在注册表单中包含了所有字段,则所有值都存储在数据库中Users
表的新记录中的相应字段中。
我不知道如何更改现有用户的字段( users
表中的行)。UserManager.UpdateAsync(user)
不工作。
还要注意,我的问题更多的是面向身份,而不是EntityFramework
https://stackoverflow.com/questions/20444022
复制相似问题