This may not be possible without writing some crazy extension method which I do not plan on doing. I know the ValidationSummary() is encoded for security. I’m just curious if I’m missing something obvious…?
I have a simple <%= Html.ValidationSummary() %> in my form. For certain situations, errors are thrown and it would be nice if I could have a little more control over the appearance of the error(s).
For example – when I import a CSV file, I throw the following error to the ValidationSummary() if the headers are not in an acceptable format or include special characters:
constraintValidatorContext.AddInvalid(invalidHeaders.Count() == 1
? string.Format("The following column header is invalid: {0}.", badHeaders)
: string.Format("There were multiple invalid column headers including: {0}.", badHeaders), "General");
It would be swell if I could display the multiple headers in a list as follows:
string.Format("There were multiple invalid column headers including: <li>{0}</li>", badHeaders)
This displays the HTML. Even if I could just throw in a NewLine here or there, it would be helpful (\n \r)… Am I just ignorant of something?
Newlines have no effect in HTML, you want a
<br />tag.You could always roll your own to get more control over the output. Here’s the MVC2 source for that helper. It basically looks through the
ValidationSummaryValidCssClassName is “validation-summary-errors” and ValidationSummaryValidCssClassName is “validation-summary-valid”.