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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:32:04+00:00 2026-06-12T14:32:04+00:00

I’m using a base contact model which other custom contact models classes inherit. public

  • 0

I’m using a base contact model which other custom contact models classes inherit.

public class BaseContactModel
{
    [Required(ErrorMessage = "Firstname is required")]
    public virtual string FirstName { get; set; }
}

The base contact model uses validation attributes to flag a property is required but in some cases I want to override or stop that. Is this going to be possible?

public class ContactModel : BaseContactModel
{
    [NotRequired]
    public override string FirstName { get; set; }
}

I attempted to use a new validation attribute NotRequired to just return true, but appears the attributes are just being stacked up so Required & NotRequired are running and the validation is failing.

On looking for solutions (which I couldn’t find) I found that some unrelated attributes have an ‘inherited’ property, but I don’t see this in the native validation attributes in System.ComponentModel.DataAnnotations.

Is this a lost cause? Do I need to roll my own versions which would support disabling inheritance? Any help greatly appreciated.

  • 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-12T14:32:05+00:00Added an answer on June 12, 2026 at 2:32 pm

    See this below, I’ve created one class Model that inherits from another BaseModel, used the new keyword then validated one of each instance. From what I can see, they both use the base attributes.

    I’ve added a control class ControlModel for clarity on the validation routine.

    class Program
    {
        static void Main(string[] args)
        {
            ValidationTest<Model>();
            ValidationTest<BaseModel>();
            ValidationTest<ControlModel>();
    
            Console.Read();
        }
    
        private static void WriteAttributeInfo<T>()
        {
            Console.WriteLine(string.Concat(typeof(T), " attributes:"));
            typeof(T).GetProperties().SelectMany(m => m.GetCustomAttributes(true)).Select(a => { Console.WriteLine(a); return a; }).ToList();
        }
    
        private static void ValidationTest<T>()
        {
            object obj = Activator.CreateInstance<T>();
            Console.WriteLine(string.Concat(typeof(T), " test: isValid = ", Validator.TryValidateObject(obj, new ValidationContext(obj, serviceProvider: null, items: null), new List<ValidationResult>())));
        }
    }
    
    class ControlModel
    {
        public string FirstName { get; set; }
    
        public string Email { get; set; }
    }
    
    class BaseModel
    {
        [RequiredAttribute]
        public virtual string FirstName { get; set; }
    
        [RequiredAttribute]
        public virtual string Email { get; set; }
    }
    
    class Model : BaseModel
    {
        public new string FirstName { get; set; }
    
        public new string Email { get; set; }
    }
    

    ConsoleApplication1.Model test: isValid = False

    ConsoleApplication1.BaseModel test: isValid = False

    ConsoleApplication1.ControlModel test: isValid = True

    From this example, it appears you can’t override/hide/ignore inherited required validation (haven’t tried others yet) attributes.

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words

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.