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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:21:06+00:00 2026-05-26T08:21:06+00:00

If two of textboxes fail validation at once then the ValidationSummary displays the same

  • 0

If two of textboxes fail validation at once then the ValidationSummary displays the same message twice.

Am I doing something wrong? Or is there a setting I can change to hide duplicate messages?

 

I have broken it down to the simplest example:

View:

@model MyModel
@Html.ValidationSummary()
@Html.TextBoxFor(model => model.A)
@Html.TextBoxFor(model => model.B)

Model:

public class MyModel : IValidatableObject
{
    public int A { get; set; }
    public int B { get; set; }

    public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
    {
        //Some logic goes here.        
        yield return new ValidationResult("Validation failed", new[] { "A", "B" });
    }
}

Result:

enter image description here

  • 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-26T08:21:07+00:00Added an answer on May 26, 2026 at 8:21 am

    They are not duplicate from the point of view of ValidationSummary – you are assigning model state error to both fields A and B, so there must be 2 errors in validation summary. It doesnt “know” that they are the same.

    Easy solutions :

    • assign model only to one of them
    • exclude property-assigned errors from summary – Html.ValidationSummary(true)

    A little bit harder solution :

    • make your own ValidationSummary helper, call standard validation summary logic in it, and then filter the result in “select distinct” way (linq is your friend here).

    EDIT:

    something like this for example :

    public static class ValidationExtensions
    {
        public static MvcHtmlString FilteredValidationSummary(this HtmlHelper html)
        {
            // do some filtering on html.ViewData.ModelState 
            return System.Web.Mvc.Html.ValidationExtensions.ValidationSummary(html);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are two textboxes one for email and other one for phone i have
I need to populate the date time values in two textboxes at a same
For example, I want to make two textboxes have the same style when either
I have two textboxes which uses the same class (they both need to be
Lets say there are two textboxes, one to enter in a date and the
I have two textboxes (part of a form), in the same line, and under
I've got a WPF view with two textboxes. I'd like to automatically move focus
I have user control named DateTimeUC which has two textboxes on its markup: <asp:TextBox
I am coding a simple login UserControl with two TextBoxes (Username and Password) and
I'm using the jQuery datepicker where I have two textboxes (start date / end

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.