Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Newlines have no effect in HTML, you want a <code>&lt;br /&gt;</code> tag.</p> <p>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 </p> <pre><code>public static MvcHtmlString ValidationSummary(this HtmlHelper htmlHelper, bool excludePropertyErrors, string message, IDictionary&lt;string, object&gt; htmlAttributes) { if (htmlHelper == null) { throw new ArgumentNullException("htmlHelper"); } FormContext formContext = htmlHelper.ViewContext.GetFormContextForClientValidation(); if (formContext == null &amp;&amp; htmlHelper.ViewData.ModelState.IsValid) { return null; } string messageSpan; if (!String.IsNullOrEmpty(message)) { TagBuilder spanTag = new TagBuilder("span"); spanTag.SetInnerText(message); messageSpan = spanTag.ToString(TagRenderMode.Normal) + Environment.NewLine; } else { messageSpan = null; } StringBuilder htmlSummary = new StringBuilder(); TagBuilder unorderedList = new TagBuilder("ul"); IEnumerable&lt;ModelState&gt; modelStates = null; if (excludePropertyErrors) { ModelState ms; htmlHelper.ViewData.ModelState.TryGetValue(htmlHelper.ViewData.TemplateInfo.HtmlFieldPrefix, out ms); if (ms != null) { modelStates = new ModelState[] { ms }; } } else { modelStates = htmlHelper.ViewData.ModelState.Values; } if (modelStates != null) { foreach (ModelState modelState in modelStates) { foreach (ModelError modelError in modelState.Errors) { string errorText = GetUserErrorMessageOrDefault(htmlHelper.ViewContext.HttpContext, modelError, null /* modelState */); if (!String.IsNullOrEmpty(errorText)) { TagBuilder listItem = new TagBuilder("li"); listItem.SetInnerText(errorText); htmlSummary.AppendLine(listItem.ToString(TagRenderMode.Normal)); } } } } if (htmlSummary.Length == 0) { htmlSummary.AppendLine(_hiddenListItem); } unorderedList.InnerHtml = htmlSummary.ToString(); TagBuilder divBuilder = new TagBuilder("div"); divBuilder.MergeAttributes(htmlAttributes); divBuilder.AddCssClass((htmlHelper.ViewData.ModelState.IsValid) ? HtmlHelper.ValidationSummaryValidCssClassName : HtmlHelper.ValidationSummaryCssClassName); divBuilder.InnerHtml = messageSpan + unorderedList.ToString(TagRenderMode.Normal); if (formContext != null) { // client val summaries need an ID divBuilder.GenerateId("validationSummary"); formContext.ValidationSummaryId = divBuilder.Attributes["id"]; formContext.ReplaceValidationSummary = !excludePropertyErrors; } return divBuilder.ToMvcHtmlString(TagRenderMode.Normal); } </code></pre> <p>ValidationSummaryValidCssClassName is "validation-summary-errors" and ValidationSummaryValidCssClassName is "validation-summary-valid".</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload