这通常是由于未正确定义ConfirmEmailModel中的属性导致的。您可以在ConfirmEmailModel类中添加以下属性:
[BindProperty(SupportsGet = true)] public string UserId { get; set; }
[BindProperty(SupportsGet = true)] public string Code { get; set; }
之后,确保在OnGetAsync方法中正确使用这些属性来获取数据并执行后续操作。
public async Task
var user = await _userManager.FindByIdAsync(userId);
if (user == null)
{
return NotFound($"Unable to load user with ID '{userId}'.");
}
var result = await _userManager.ConfirmEmailAsync(user, code);
if (!result.Succeeded)
{
throw new InvalidOperationException($"Error confirming email for user with ID '{userId}':");
}
return Page();
}