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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:41:31+00:00 2026-05-14T18:41:31+00:00

Basically, what the title says. I have several properties that combine together to really

  • 0

Basically, what the title says. I have several properties that combine together to really make one logical answer, and i would like to run a server-side validation code (that i write) which take these multiple fields into account and hook up to only one validation output/error message that users see on the webpage.

I looked at scott guthries method of extending an attribute and using it in your dataannotations declarations, but, as i can see, there is no way to declare a dataannotations-style attribute on multiple properties, and you can only place the declarations (such as [Email], [Range], [Required]) over one property :(.

i have looked at the PropertiesMustMatchAttribute in the default mvc 2.0 project that appears when you start a new project, this example is as useful as using a pair of pins to check your motor oil – useless!

i have tried this method, however, creating a class level attribute, and have no idea how to display the error from this in my aspx page. i have tried html.ValidationMessage(“ClassNameWhereAttributeIsAdded”) and a variety of other things, and it has not worked. and i should mention, there is NOT ONE blog post on doing validation at this level – despite this being a common need in any project or business logic scenario!

can anyone help me in having my message displayed in my aspx page, and also if possible a proper document or reference explaining validation at this level?

  • 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-14T18:41:31+00:00Added an answer on May 14, 2026 at 6:41 pm

    Now that you’ve looked at Data Annotations and arrived to the conclusion that they are not adapted to your scenario I would suggest you looking at FluentValidation, its integration with ASP.NET MVC and the way you would unit test your validation logic – you won’t be disappointed (I really have nothing against Data annotations, they are great for blog posts and tutorials but once you are confronted to real world applications you quickly realize the limits).


    UPDATE:

    As requested in the comments section here’s an example of using the FluentValidation framework with one server-side validation function accessing multiple properties (please don’t do this as it is ugly and there’s a better way):

    class AuthInfo
    {
        public string Username { get; set; }
        public string Password { get; set; }
        public string ConfirmPassword { get; set; }
    }
    
    class AuthInfoValidator : AbstractValidator<AuthInfo>
    {
        public override ValidationResult Validate(AuthInfo instance)
        {
            var result = base.Validate(instance);
            if (string.IsNullOrEmpty(instance.Username))
            {
                result.Errors.Add(new ValidationFailure("Username", "Username is required"));
            }
            if (string.IsNullOrEmpty(instance.Password))
            {
                result.Errors.Add(new ValidationFailure("Password", "Password is required"));
            }
            if (string.IsNullOrEmpty(instance.ConfirmPassword))
            {
                result.Errors.Add(new ValidationFailure("ConfirmPassword", "ConfirmPassword is required"));
            }
            if (instance.Password != instance.ConfirmPassword)
            {
                result.Errors.Add(new ValidationFailure("ConfirmPassword", "Passwords must match"));
            }
            return result;
        }
    }
    

    The more natural way to do this is the following (it is also immune to property rename as it contains no magic strings):

    class AuthInfoValidator : AbstractValidator<AuthInfo>
    {
        public AuthInfoValidator()
        {
            RuleFor(x => x.Username)
                .NotEmpty()
                .WithMessage("Username is required");
    
            RuleFor(x => x.Password)
                .NotEmpty()
                .WithMessage("Password is required");
    
            RuleFor(x => x.ConfirmPassword)
                .NotEmpty()
                .WithMessage("ConfirmPassword is required");
    
            RuleFor(x => x.ConfirmPassword)
                .Equal(x => x.Password)
                .WithMessage("Passwords must match");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what the title says. I have several properties that combine together to really
Basically what the title says... I need to have an image that when clicked,
The title pretty much says it all, but basically I have a main parent
The title basically says it all. I have a hexadecimal string representing a private
Basically the title is my question. I have a project in one of my
the title basically says it, i have a from with a treeview and a
The title basically says it all. In my case, I have a polyline and
Basically, as the title says... is there any way to have user input directly
I'm confused on how to do what the title says. Basically I have two
The title basically says it all. I mainly want to do this so that

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.