I have a registration page, if the user types an email address that's already registered I need to output a link for them to login in the validation message.
However, validation tag helpers HTML encode error messages, so the link is displayed as HTML.
In the view:
@model Site.ViewModels.RegisterEmail
<h1>Register</h1>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="Email">
<div class="form-group">
<label asp-for="Email" class="control-label"></label>
<input asp-for="Email" class="form-control" />
<span asp-validation-for="Email" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Continue" class="btn btn-default" />
</div>
</form>
</div>
</div>
In the controller:
var LoginLink = $"<a href='{Request.Scheme}://{Request.Host}{Request.PathBase}/Login'>Login</a>";
if (CustomerRepo.CustomerEmailExists(RegisterEmail.Email))
ModelState.AddModelError("Email", $"Email already registered. {LoginLink} with your email, or register below");
How can I prevent the validator HTML encoding, or otherwise properly display the HTML link in the validation message?
I can't find anything on Google about this.
Thanks.
HtmlHelperextension method)