save new data to user table using asp identity

2019-09-20 00:40发布

I am trying to add a piece of data to the Asp identity table which stores user details (AspNetUsers). I have code to create a new user but not how to add or change things in a table. Could someone link me a resource or show me an example of how to do this?

For example if I created users where age was null and had a form that asked a user to input an age and wanted to add that to the users information without having to create a new user.

I have all the code to collect the variable.

I have added migrations for the new columns and created the columns in the table, I just need to add the data for the user that is currently logged in.

1条回答
别忘想泡老子
2楼-- · 2019-09-20 00:54

Have you tried this

var user = await UserManager.FindByNameAsync(User.Identity.Name);
user.Age = 25;
IdentityResult result = await UserManager.UpdateAsync(user);
查看更多
登录 后发表回答