I am trying to display a strong tag inside a validation summary but it encodes it and does not display properly.
@Html.ValidationSummary(false, "<strong>ERROR:<strong>The form is not valid!")
How can I get this to work?
The easiest way:
@if (!ViewData.ModelState.IsValid)
{
<div>@Html.Raw(HttpUtility.HtmlDecode(Html.ValidationSummary(false, "<strong>ERROR:<strong>The form is not valid!").ToHtmlString()))</div>
}
I've find this :
public static MvcHtmlString ToMvcHtmlString(this MvcHtmlString htmlString)
{
if (htmlString != null)
{
return new MvcHtmlString(HttpUtility.HtmlDecode(htmlString.ToString()));
}
return null;
}
and then :
@Html.ValidationSummary(false, "<strong>ERROR:<strong>The form is not valid!").ToMvcHtmlString()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With