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

  • Home
  • SEARCH
  • 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 8884851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:09:49+00:00 2026-06-14T21:09:49+00:00

A similar question has been asked before ( Custom ValidationSummary template Asp.net MVC 3

  • 0

A similar question has been asked before (Custom ValidationSummary template Asp.net MVC 3) but neither of the answers satisfy the extra requirement I have, which is that the solution doesn’t break client-side validation.

So, does anyone know a way to get functionality like this:

@if (!ViewData.ModelState.IsValid)
{
    <div class="form-errors">
        <p>Please have another look at the fields highlighted below</p>
        @Html.ValidationSummary()
    </div>
}

that works with client-side validation?

This does exactly what I want when client-side validation is off, i.e., excludes the whole div if the model is valid, displays it if there are any errors. However, the conditional means that when the form is first rendered when the evaluation is false, the entire section is not rendered, so jquery.validate can’t find any place to insert the validation summary.

Any ideas?

  • 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-06-14T21:09:50+00:00Added an answer on June 14, 2026 at 9:09 pm

    helper:

        public static MvcHtmlString MyValidationSummary(this HtmlHelper helper, bool excludePropertyErrors = false)
        {
            string html = "";
    
            html += helper.ViewData.ModelState.IsValid ? "<div class='form-errors' style='display:none;'>" : "<div class='form-errors'>";
    
            html += "<p>Please have another look at the fields highlighted below</p>";
            html += helper.ValidationSummary(excludePropertyErrors);
            html += "</div>";
    
            return new MvcHtmlString(html);
        }
    

    View:

    @using (Html.BeginForm("Index", "Home",FormMethod.Post, new {id="myform"}))
    {
        @Html.MyValidationSummary()
        ...
        <input type="button" id="submitbutton" value="Submit" />
    }
    

    JS:

    $("#submitbutton").click(function () {
        $("#myform").validate();
    
        if (!$("#myform").valid()) {
            $("#myform .form-errors").show();
        }
        else {
            $("#myform").submit();
        }
    });
    

    Update:

    If you want to go with the partial view

    Shared/_MyValidationSummary.cshtml

    @if (!ViewData.ModelState.IsValid)
    {
        <div class="form-errors">
            <p>Please have another look at the fields highlighted below</p>
            @Html.ValidationSummary()
        </div>
    }
    else
    {
        <div class="form-errors" style="display:none;">
            <p>Please have another look at the fields highlighted below</p>
            @Html.ValidationSummary()
        </div>
    }
    

    View:

    @using (Html.BeginForm("Index", "Home",FormMethod.Post, new {id="myform"}))
    {
        @Html.Partial("_MyValidationSummary")
        ...
        <input type="button" id="submitbutton" value="Submit" />
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

a similar question has been asked before , but the answers suggested a workaround
Hey a similar question has been asked before, but none that answers mine exactly.
A similar question has been asked before by someone else , but there were
I know a similar question has been asked before but it seemed never been
I know this question has been asked in a similar fashion before, but I
Preface I'm aware a similar question has been asked before, but I believe my
I am not sure if a similar question has been asked before, searched for
I know a similar question has been asked but I have not found a
Apologies if this question has been asked before, I couldn't find anything similar. I
I'm sorry, I'm sure a similar question has already been asked but I'm afraid

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.