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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:43:30+00:00 2026-05-15T16:43:30+00:00

Update after Bounty was awarded A new solution is coming up to this problem.

  • 0

Update after Bounty was awarded

A new solution is coming up to this problem. Please refer to ASP.NET MVC 3 Preview 1 here: http://weblogs.asp.net/scottgu/archive/2010/07/27/introducing-asp-net-mvc-3-preview-1.aspx

Look in the section Model Validation Improvements, where you will see the solution to my problem.


Original Post

Referring to my earlier post How to validate two properties with ASP.NET MVC 2 where I asked how I could compare two properties for Model validation.

I did find the answer useful, but I was left with an entirely different problem:

Problem: If a Property-level ValidationAttribute contains an error, then the Class-level ValidationAttributes are NOT validated.

Please consider the following:

[EqualTo("Email", "EmailConfirm", ErrorMessage = "E-mailadresserne skal være ens")]
[EqualTo("Password", "PasswordConfirm", ErrorMessage = "Adgangskoderne skal være ens")]
[Bind(Exclude="UserId")]
public class EditSiteUser
{
    [Required(ErrorMessage="Du skal bekræfte adgangskode")]
    public string PasswordConfirm { get; set; }

    [Required(ErrorMessage="Du skal bekræfte e-mailadressen")]
    [Email(ErrorMessage="Ugyldig e-mailadresse")]
    public string EmailConfirm { get; set; }
    public int UserId { get; set; }

    [Required(ErrorMessage = "Du skal indtaste et brugernavn")]
    public string Username { get; set; }

    [Required(ErrorMessage = "Du skal indtaste en adgangskode")]
    public string Password { get; set; }

    [Required(ErrorMessage = "Du skal indtaste en e-mailadresse")]
    [Email(ErrorMessage = "Ugyldig e-mailadresse")]
    public string Email { get; set; }
}

Here I have two Class-level attibutes that validate EmailConfirm and PasswordConfirm.

If a field like Username is empty, and thus yields an error, then the two EqualTo Attributes are never validated.

Does anyone have a suggestion to overcome this problem?

EDIT: If you need anymore information about this problem, please ask in comments and I will be very happy to give you any additional information you need.

Questions:

Q: “Why is it important that the class-level checks get validated if a property-level check fails?”.

A: “Because this is part of a form, where a user enters information into a form that posts back via AJAX. When the form returns it should show all current problems.”

Q: “What exactly is the EqualTo attribute you have placed on the class? Is it a custom validation attribute? If so, how does it work? what does it do?”

A: EqualTo is a class-level ValidationAttribute that compares the value of two Properties of the class-instance. Look up “PropertiesMustMatchAttribute” for a similar implementation.

  • 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-15T16:43:30+00:00Added an answer on May 15, 2026 at 4:43 pm

    This isn’t supported. If any of the property level validations fail, then the class level validations are not performed. I suggest you look at MVC Foolproof Validation. It extends MVC validation to add support for contingent property validation. I think that would solve the problem for this particular case.

    The project site states that it doesn’t work with the MVC2 RC, so you’ll have to download the source code and get it running/adopt their ideas yourself.

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

Sidebar

Related Questions

I have found this example on StackOverflow: var people = new List<Person> { new
I would like to update my SQL lite database with the native update-method of
I would like to remove/delete a migration file. How would I go about doing
I have a login.jsp page which contains a login form. Once logged in the
I am using a 3rd-party rotator object, which is providing a smooth, random rotation
I'm trying to write test harness for part of my Android mapping application. I

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.