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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:15:02+00:00 2026-05-16T18:15:02+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 yoru 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 :(.

any ideas on how to go about this? preferably without having to go the whole AssociateValidatorProvider route? as i found thisdifficult to grasp mainly since people never tell you ‘why’ they are doing what they are doing in enough detail to make me feel comfortable.

at the moment, i’ve tried ot create a dummy hidden field on the form with the [Required] attribute on it, and i set it to an empty string when my multi-field custom validation code predicts an error, which shoudl trigger an error message, but not even that works, because when i change the values of these fields AFTER the action is received, the modelstate isn’t updated with this info so presumes submitted values, and doing an UpdateModel fails with an error. on top of these errors, i suppose it isn’t the elegant way to do things. so i’m listening to anything you guys suggest.

  • 1 1 Answer
  • 1 View
  • 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-16T18:15:03+00:00Added an answer on May 16, 2026 at 6:15 pm

    You can add those validation messages into the ModelState errors and display them on client side using Jquery/JavaScript.

    If your action method return JsonResult then return the errors as JsonResult else set the errors into ViewData and then access and display them at the client side.

    You can add the custom errors into the model state as follows :

     if(your custom validation fails....)
     {
         ModelState.AddModelError("Error1", "Your Error message1");
         ModelState.AddModelError("Error2", "Your Error message2");
     }
    
     if (!ModelState.IsValid)
     {
         return new JsonResult() { Data = GetModelStateErrors(ModelState)};
     }
    
     private static Collection<string> GetModelStateErrors(ModelState modelState)
      {
           Collection<string> errors = new Collection<string>();
    
           foreach (var item in modelState.Values)
           {
                foreach (var item2 in item.Errors)
                {
                    if (!string.IsNullOrEmpty(item2.ErrorMessage))
                    {
                        errors.Add(item2.ErrorMessage);
    
                    }
                }
           }
           return errors;
      }
    
    • 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
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 description basically says it all. I'd like to use something that requires
The title basically says it all. Suppose I have an element which I want

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.