将电子邮件传递给 ResendEmailConfirmation model/view - Identity
Pass email to ResendEmailConfirmation model/view - Identity
我正在尝试将用户的电子邮件从注册页面传递到身份的 ResendEmailConfirmation.cshtml class,以便它显示在电子邮件输入框中的视图中。
注册页面 - link 将用户重定向到“重新发送电子邮件确认”页面
<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 - 相关部分
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 视图 - 电子邮件输入框
<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>
谢谢
您应该使用这种方式在 OnGet() 中定义输入:
Register.cshtml.cs 获取邮件(你没有显示这部分代码,所以我直接定义值):
public void OnGet()
{
Input =new InputModel()
{
Email = "asd@asd.com"
};
}
然后ResendEmailConfirmation.cshtml.cs显示从注册页面传递过来的电子邮件:
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
};
}
您不必更改 Razor 视图页面。
结果:
我正在尝试将用户的电子邮件从注册页面传递到身份的 ResendEmailConfirmation.cshtml class,以便它显示在电子邮件输入框中的视图中。
注册页面 - link 将用户重定向到“重新发送电子邮件确认”页面
<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 - 相关部分
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 视图 - 电子邮件输入框
<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>
谢谢
您应该使用这种方式在 OnGet() 中定义输入:
Register.cshtml.cs 获取邮件(你没有显示这部分代码,所以我直接定义值):
public void OnGet()
{
Input =new InputModel()
{
Email = "asd@asd.com"
};
}
然后ResendEmailConfirmation.cshtml.cs显示从注册页面传递过来的电子邮件:
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
};
}
您不必更改 Razor 视图页面。
结果: