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”) { }}

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: