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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:40:36+00:00 2026-06-04T05:40:36+00:00

For a simple validation of multiple required fields i am using a custom validator

  • 0

For a simple validation of multiple required fields i am using a custom validator explained here

I am getting the desired behavior and validation summary message is displayed correctly, but what i am missing now is the lack of validation error css class on invalid input elements,
which is added when built-in validators are used.

This is the correct behavior:

<input class="input-validation-error" name="ModelName" ... />

And this is what i get when using mentioned custom validator:

<input name="ModelName" ... />

Please note that i am referring to server side validation.

UPDATE

This is my model:

public class Register
{
        [MultiFieldRequired(new[] { "Name", "UserName" }, ErrorMessage = "Please provide all required information")]
        [Display(Name = "Name")]
        public string Name { get; set; }

        [MultiFieldRequired(new[] { "Name", "UserName" }, ErrorMessage = "Please provide all required information")]
        [Display(Name = "User name")]
        public string UserName { get; set; }
}

And this is the rendered output:

<input class="text-box single-line" data-val="true" data-val-multifield="Please provide all required information" id="Name" name="Name" type="text" value="" />
<input class="text-box single-line" data-val="true" data-val-multifield="Please provide all required information" id="UserName" name="UserName" type="text" value="" />

I am now realizing that the problem i had only occurs when i decorate my entire model class with the MultiFieldRequired attribute:

[MultiFieldRequired(new[] { "Name", "UserName" }, ErrorMessage = "Please provide all required information")]
public class Register
{
...

In this case no invalid field has modified css class, while in the other scenario, when i annotate every field in the model i get the same error message multiplied by the number of invalid fields.

So, to summarize – i want to have one error message regardless of the
number of invalid fields and I also want that each invalid field be
marked with .input-validation-error class.

  • 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-04T05:40:37+00:00Added an answer on June 4, 2026 at 5:40 am

    I was expecting that invalid fields in the view will be marked with .input-validation-error class regardles of the position of the attribute, so i used the custom validator attribute to annotate my model class like this:

    [MultiFieldRequired(new[] { "Name", "UserName" }, ErrorMessage = "Please provide all required information")]
    public class Register
    {
            [Display(Name = "Name")]
            public string Name { get; set; }
    
            [Display(Name = "User name")]
            public string UserName { get; set; }
    }
    

    On the other hand, if i annotate each field:

    public class Register
    {
            [MultiFieldRequired(new[] { "Name", "UserName" }, ErrorMessage = "Please provide all required information")]
            [Display(Name = "Name")]
            public string Name { get; set; }
    
            [MultiFieldRequired(new[] { "Name", "UserName" }, ErrorMessage = "Please provide all required information")]
            [Display(Name = "User name")]
            public string UserName { get; set; }
    }
    

    my view generates multiple identical messages in the validation summary.

    So i ended up having a a custom validation summary error message using ValidationSummary like this:

    @Html.ValidationSummary(true, "Please provide all required information")
    

    and my fields are decorated with simple asterisks like this:

    public class Register
    {
            [Required(ErrorMessage = "*")]
            [Display(Name = "Name")]
            public string Name { get; set; }
    
            [Required(ErrorMessage = "*")]
            [Display(Name = "User name")]
            public string UserName { get; set; }
    }
    

    At the end, my view is rendered like this:

    Validation error messages

    HTH

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

Sidebar

Related Questions

I want to perform simple validation against multiple fields. Please note these fields are
I have a simple form and would like to add a custom jQuery validation
I'm trying to create a simple custom validator for my project, and I can't
I am using org.apache.commons.validator.routines.DateValidator to validate a date with a simple date pattern dd/mm/yyyy
Fields on the site are validated using JQuery Validate: http://bassistance.de/jquery-plugins/jquery-plugin-validation/ When there's one e-mail,
Does anyone have a simple example of implementing an async validation rule in csla?
I try to use the client side validation on a very simple example and
Im trying to create a simple input box with form validation, but im not
I am using JSF validation to simply check that the length of a field
I have a PHP form that needs some very simple validation on submit. I'd

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.