I'm trying to pass the user's email to Identity's ResendEmailConfirmation.cshtml class from the register page, so that it is displayed on view in the Email Input box.
Register Page - The link to redirect the user to the Resend Email Confirmation page
<a asp-area="Identity" asp-page="/Account/resendemailconfirmation" asp-route-email="@Model.Input.Email" class="resend-confirm-email-submit">Resend confirmation email</a>
ResendEmailConfirmation.cshtml - Relevant Parts
public ResendEmailConfirmationModel(UserManager<IdentityUser> userManager, IEmailSender emailSender)
{
_userManager = userManager;
_emailSender = emailSender;
}
[BindProperty]
public InputModel Input { get; set; }
public class InputModel
{
[Required]
[EmailAddress]
public string Email { get; set; }
}
public void OnGet(string email)
{
// My attempt
InputModel inputModel = new InputModel();
inputModel.Email = email;
}
ResendEmailConfirmation View - Email Input Box
<form method="post">
<div asp-validation-summary="All" class="text-danger"></div>
<div class="form-group">
<label asp-for="Input.Email" class="register-heading-style"></label>
<input asp-for="Input.Email" class="form-control" />
<span asp-validation-for="Input.Email" class="text-danger"></span>
</div>
@*<button type="submit" class="btn btn-primary">Resend</button>*@
<button type="submit" class="register-submit"><span>Resend</span></button>
</form>
Thank you
You should use this way to define Input in OnGet():
Register.cshtml.cs to get the email (You didn't show this part of code, so I directly define the value):
public void OnGet()
{
Input =new InputModel()
{
Email = "[email protected]"
};
}
Then ResendEmailConfirmation.cshtml.cs to show the email that passed from register page:
public void OnGet(string email)
{
Input = new InputModel() //you get value from Input.Eamil in view, so you should define Input, not inputmodel
{
Email = email
};
}
You do not have to change the razor view pages.
Result: