Custom DataAnnotations

This is using Notation: The DateTime will look for a DateTimeAttribute extended from RangeAttribute.  THis is good when you cannot use non constants as range string values.

[DateTime(ErrorMessage= “”)]
public DateTime SomeDateTimeVariableName

Create an a class extended from RangeAttribute.

public class DateTimeAttribute : RangeAttribute
{
public DateTimeAttribute()
: base(typeof(DateTime), string.Format(“{0} {1}”, DateTime.Now.ToString(“M/dd/yyyy”), “12:00:00 AM”), “12/31/2099”) { }}

Share on Facebook

Leave a Reply

Your email address will not be published.