Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4270464
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:18:36+00:00 2026-05-21T07:18:36+00:00

This may not be possible without writing some crazy extension method which I do

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T07:18:36+00:00Added an answer on May 21, 2026 at 7:18 am

    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

    public static MvcHtmlString ValidationSummary(this HtmlHelper htmlHelper, bool excludePropertyErrors, string message, IDictionary<string, object> htmlAttributes) {
            if (htmlHelper == null) {
                throw new ArgumentNullException("htmlHelper");
            }
    
            FormContext formContext = htmlHelper.ViewContext.GetFormContextForClientValidation();
            if (formContext == null && 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<ModelState> 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);
        }
    

    ValidationSummaryValidCssClassName is “validation-summary-errors” and ValidationSummaryValidCssClassName is “validation-summary-valid”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may be a silly question to a graphics guru (which I am not),
this may or may not be possible (and could well be in the docs
This may not be the correct way to use controllers, but I did notice
This may not really sound hard to do but it is currently killing me.
This is one of those meta-programming questions that may or may not belong on
Okay, this may be a dumb question, but I've not been able to find
I hope this question does not come off as broad as it may seem
This may be a no-brainer for the WPF cognoscenti, but I'd like to know
I am thinking about some issues which may match the term software integration best.
I know this question may be wrong one.Anyway I want to know is it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.