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 6164535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:00:34+00:00 2026-05-23T22:00:34+00:00

I want to know if Html.ValidationSummary is present in code. The tag div class=validation-summary-valid

  • 0

I want to know if Html.ValidationSummary is present in code. The tag div class="validation-summary-valid" is not present in html if Html.ValidationSummary has a parameter of true. i.e. Html.ValidationSummary(true), the result, there’s no reliable way to know in jquery if Html.ValidationSummary is in code.

Is there a property that says so? The presence or absence of Html.ValidationSummary

[EDIT: clarification]

Putting Html.ValidationSummary with a parameter of true:

@using (Html.BeginForm()) {

    @Html.ValidationSummary(true)   

    <b>Hello</b>

,and not putting any Html.ValidationSummary:

@using (Html.BeginForm()) {

    <b>Hello</b>

,both code yields the same HTML(View Page Source):

    <b>Hello</b>

That being so, there’s no reliable way from jQuery to know if Html.ValidationSummary is present or not in the code

  • 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-23T22:00:36+00:00Added an answer on May 23, 2026 at 10:00 pm

    It is happening because ValidationSummary helper does not return empty <div class="validation-summary-errors"/> if there is no errors (when ViewData.ModelState.IsValid returns true). In such case you need to have custom ValidationSummary which fixing that:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Text;
    
    namespace System.Web.Mvc
    {
        public static class HtmlHelpers
        {
            public static MvcHtmlString CustomValidationSummary(this HtmlHelper helper, string validationMessage = null)
            {
    
                StringBuilder summary = new StringBuilder();
    
                summary.Append("<div class=\"validation-summary-errors\">");
    
                if (helper.ViewData.ModelState.IsValid)
                {
                    summary.Append("</div>");
    
                    return new MvcHtmlString(summary.ToString());
                }
    
                else if (!string.IsNullOrEmpty(validationMessage))
                {
                    summary.Append("<ul>");
                    summary.AppendFormat("<li>{0}</li>", validationMessage);
    
                    summary.Append("</ul>");
                    summary.Append("</div>");
    
                    return new MvcHtmlString(summary.ToString());
                }
    
    
                summary.Append("<ul>");
    
                foreach (KeyValuePair<string, ModelState> state in helper.ViewData.ModelState)
                {
                    foreach (ModelError error in state.Value.Errors)
                    {
                        summary.AppendFormat("<li>{0}</li>", HttpUtility.HtmlEncode(error.ErrorMessage));
                    }
    
                }
    
                summary.Append("</ul>");
                summary.Append("</div>");
    
                return new MvcHtmlString(summary.ToString());
            }
        }
    }
    

    This custom ValidationSummary helper will generate empty validation-summary-errors div even if there is was no errors, other words <div class="validation-summary-errors"/> would be present in your html every time, like you want.

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

Sidebar

Related Questions

I want to know, how to make my html file code to encrypted? So
I want to know how I can add these attributes to my html tag
I want to know the input html string is vaild or not. I researched
i want to know the width and height of the html elements like divs
I want to open html files from a shell script. I know that Ubuntu
I want to know what a virtual base class is and what it means.
I know HTML&Css, Little Javascript & Little PHP. I really want to get in
I want to know the order of loading the CSS files in a HTML
Ok so I want to know how <% using (Html.BeginForm()) { %> <input type=text
i have a HTML page that want to encode it so could not decode

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.