使用ASP身份将新数据保存到用户表 [英] save new data to user table using asp identity

查看:73
本文介绍了使用ASP身份将新数据保存到用户表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向存储用户详细信息(AspNetUsers)的Asp身份表中添加一条数据.我有创建新用户的代码,但没有如何在表中添加或更改内容的代码.有人可以给我链接资源或向我展示如何执行此操作的示例吗?

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.

推荐答案

您是否尝试过

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

这篇关于使用ASP身份将新数据保存到用户表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆