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

The Archive Base Latest Questions

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

I’m trying to setup data annotation validation for an object in my model and

  • 0

I’m trying to setup data annotation validation for an object in my model and it has a special need. I have to essentially take some extra properties that I’m adding and combine them to get the value of a real property. For example I have a base object:

Task {
    public DateTime? Due
}

But my form has the fields of:

Task.DueDate
Task.DueTimeHour
Task.DueTimeMinute
Task.DueTimePostfix

So I tried:

Task {
    public string DueDate
    public string DueTimeHour
    public string DueTimeMinute
    public string DueTimePostfix
}

Which works, but I then want the model to automatically populate the value of Due with the parsed value of all the other ones. I don’t know how to do that.

I would have to override the getter/setters of Due in the metadata buddy class, but that class wouldn’t be aware of the extra properties I’ve given to the original class. Plus I have a feeling that if I mess with those I will have problems retrieving real values from the database.

So I’m hoping that someone here may have an idea on how I can accomplish what I want. If I’m going about it completely wrong I would appreciate being guided back on the right path.

Thanks in advance for any suggestions!

UPDATE

So, I might have found a solution for the first part by having both the original class and the metadata buddy class extend from another base class which contains all the properties. Thus both classes see the properties and can use them.

Now, I’m having a hard time setting the value for the Due property based off of the other properties. Help would be appreciated on this front.

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

    So, I figured it out at the expense of only a couple of hours of sleep. Here’s my final code version that works for anyone who may have the same issues in the future:

    public partial class Task {
        public DateTime DueDate {
            get {
                return (DateTime.Now);
            }
            set {
                this.Due = value;
            }
        }
    
        [Range(0, 23)]
        public byte DueTimeHour {
            get {
                return (0);
            }
            set {
                if (this.Due.HasValue) {
                    this.Due = DateTime.Parse(this.Due.Value.ToShortDateString() + " " + value + ":00:00");
                };
            }
        }
    
        [Range(0, 59)]
        public byte DueTimeMinute {
            get {
                return (0);
            }
            set {
                if (this.Due.HasValue) {
                    this.Due = DateTime.Parse(this.Due.Value.ToString("M/d/yyyy h") + ":" + value + ":00");
                };
            }
        }
    
        public string DueTimePostfix {
            get {
                return (string.Empty);
            }
            set {
                if (this.Due.HasValue) {
                    this.Due = DateTime.Parse(this.Due.Value.ToString("M/d/yyyy h:m") + " " + value);
                };
            }
        }
    }
    

    Ultimately, I had to add a get to make it work, which makes me curious. I was hoping to get by with just the set on each property because I was already manipulating the Due value in there, but it wouldn’t work without the get. Maybe someone can explain that one to me?

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

Sidebar

Related Questions

I have some data like this: 1 2 3 4 5 9 2 6
Basically, what I'm trying to create is a page of div tags, each has
I have just tried to save a simple *.rtf file with some websites and
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.