Hi @Sherpa,
Firstly, no need encode the error message as HTML(no need use WebUtility.HtmlEncode
):
invalidLogin ="Invalid: <b>User Name</b> and/or <b>Password</b>";
ModelState.AddModelError(string.Empty, invalidLogin);
In your Razor Pages .cshtml file, get the ModelState
with key name which is empty string here, then use @Html.Raw()
to interpret the HTML tags:
@if (ModelState[""] != null && ModelState[""]?.Errors.Count!=0)
{
var error = ModelState[""]?.Errors.First().ErrorMessage;
@Html.Raw(error)
}
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Rena