首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >更新用户数据- ASP.NET标识

更新用户数据- ASP.NET标识
EN

Stack Overflow用户
提问于 2013-12-08 01:01:47
回答 12查看 104.9K关注 0票数 76

我已经向ApplicationUser类添加了定制字段

我还创建了一个表单,用户可以通过它输入/编辑字段。

但是,由于某些原因,我无法更新数据库中的字段。

代码语言:javascript
复制
[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

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20444022

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档