: , javascript, . , UX . .
, ValidationAttribute. :
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
public class EndDateAttribute : ValidationAttribute
{
public EndDateAttribute(DateTime endDate)
{
EndDate = endDate;
}
public DateTime EndDate { get; set; }
public override bool IsValid(object value)
{
if (value == null)
return false;
DateTime val;
try
{
val = (DateTime)value;
}
catch (InvalidCastException)
{
return false;
}
if (val >= EndDate)
return false;
return true;
}
}
, , , StartDate.
: . ().
[DisplayName("Effective Start Date")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
[StartDate(DateTime.Now)]
public DateTime EffectiveStartDate { get; set; }
[DisplayName("Effective End Date")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
[EndDate(new DateTime(2011, 9, 24)]
public DateTime EffectiveEndDate { get; set; }