I am trying to display a strong tag inside a validation summary but it encodes it and does not display properly.
@Html.ValidationSummary(false, \"E
I have a site that uses Resource files for language. In one of the items I placed this for the Value: <img src="images/exclamation.png" > <strong>Pharmacy Name is required</strong>
and it works.
You could extend the ValidationSummary helper as has been suggested in the accepted answer on this question.
Edit: I presume the encoding of any text entered is a security feature and therefore a good thing.
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>
}
@Html.Raw(System.Web.HttpUtility.HtmlDecode((Html.ValidationSummary(false) ?? (object)"").ToString()))
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()