save new data to user table using asp identity

佐手、 提交于 2019-12-13 07:57:57

问题


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:


Have you tried this

var user = await UserManager.FindByNameAsync(User.Identity.Name);
user.Age = 25;
IdentityResult result = await UserManager.UpdateAsync(user);


来源:https://stackoverflow.com/questions/43307810/save-new-data-to-user-table-using-asp-identity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!