gpt4 book ai didi

asp.net-mvc - 如何在 .NET Core 中更改 SQL 数据库中的 FirstName 属性?

转载 作者:行者123 更新时间:2023-12-04 08:10:40 25 4
gpt4 key购买 nike

我已经成功验证了我的应用程序,但我似乎唯一不能做的就是更改我所做的用户属性。

public async Task<IActionResult> OnPostAsync()
{
var user = await _userManager.GetUserAsync(User);

if (user == null)
{
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
}

if (!ModelState.IsValid)
{
LoadAsync(user);
return Page();
}

var phonenumber = await _userManager.GetPhoneNumberAsync(user);

if (Input.PhoneNumber != phonenumber)
{
var setPhoneNumber = await _userManager.SetPhoneNumberAsync(user, Input.PhoneNumber);
}

user.FirstName = Input.FirstName;

return RedirectToPage();
}
如果有人知道如何更改 FirstName属性(property),谢谢。

最佳答案

I have successfully authenticated my app, but the only thing that I can't seem to do is change the user properties that I have made.


您可以尝试调用 UserManager<TUser>.UpdateAsync(TUser) method更新指定的用户,如下所示。
//set FirstName of current user
user.FirstName = Input.FirstName;

//update the specified user
await _userManager.UpdateAsync(user);

关于asp.net-mvc - 如何在 .NET Core 中更改 SQL 数据库中的 FirstName 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65983073/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com