【问题标题】:Update User Details in MVC5在 MVC5 中更新用户详细信息
【发布时间】:2014-07-17 12:39:32
【问题描述】:

我正在尝试更新用户详细信息。
这是我的代码。

我的模特-

 public class ApplicationUser : IdentityUser
    {
        public string Name { get; set; }
        public string MobileNumber { get; set; }
        public string Email { get; set; }
    }

控制器-

 [HttpPost]
        public ActionResult UpdateUser(ApplicationUser UserProfile)
        {
            if (ModelState.IsValid)
            {

                var result = UserManager.Update(UserProfile);
                if (result.Succeeded)
                    return View(UserProfile);
                else
                {
                    return View(UserProfile);
                }


            }
            return View(UserProfile);
        }

"result.Error.strings" 获取值

Name suresh already taken

【问题讨论】:

  • 对不起,我很傻。正如错误提示的那样,您是否已经在 DB 中安装了 Suresh?
  • 请添加 UserManager.Update 代码

标签: asp.net asp.net-mvc asp.net-mvc-5 asp.net-identity asp.net-mvc-5.1


【解决方案1】:

根据错误消息,我猜你的数据库已经有名为Suresh的用户

如果错误仍然存​​在,请尝试其他名称更新您的问题,我希望您可以获得更多帮助。

您可以更新用户的另一种方法是先找到用户,然后更新必填字段,然后更新(保存)用户。

【讨论】:

    【解决方案2】:

    我遇到了同样的问题。发现当没有设置需要更新的用户ID时,EF上下文卧底将用户对象视为新实体。

    使用 ID 修复错误,我遇到了一个新错误,所以为了帮助任何挣扎的人(并简化几个步骤) - 我指向一个解释它的答案:

    asp.net identity 2.0 update user

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-18
      • 1970-01-01
      • 2018-01-04
      • 2014-08-21
      • 1970-01-01
      • 1970-01-01
      • 2016-08-08
      • 1970-01-01
      相关资源
      最近更新 更多