1

I am trying to update user details.
Here is my code.

My Model-

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

The Controller-

 [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" gets the value

Name suresh already taken

2 Answers2

0

Based upon the the error message, i'm guessing your Database already has the user with name Suresh

Try another name if the error still exists update your question and my be you can get more help.

The other way you could update an user could be first find the user then update the required fields then update(save) user.

Cybercop
  • 8,475
  • 21
  • 75
  • 135
0

I had the same problem. figured out that when one does not set the ID of the user that needs to be updated, the EF context undercover treats the user object as the new entity.

fixing the error with the ID, I've got a new error, so to help anyone struggling (and to scip a couple of steps) - I pointing to an answer that explains it:

asp.net identity 2.0 update user

Community
  • 1
  • 1
Igarioshka
  • 677
  • 3
  • 14