このクラスはDateTimeViewModelNullableと呼ばれ、DateTimeを返すメソッドがありますか?2つのdatetimeプロパティのうちの1つがasp.netの別のものより大きいかどうかをテストするカスタムバリデータを実行する方法mvc3
public DateTime? GetDateTime
{
get
{
DateTime date;
if (DateTime.TryParse(Date, CultureInfo.CurrentCulture, DateTimeStyles.None, out date))
{
try
{
return new DateTime(date.Year, date.Month, date.Day, ParseInt(Hour), ParseInt(Minute), 0, DateTimeKind.Utc);
}
catch (ArgumentException)
{
return null;
}
}
return null;
}
}
Iはその後のviewmodel 公共DateTimeViewModelNullable DateOut {取得にそのタイプの2つの特性を有します。セット;私はエラーエラーにオブジェクトを取得STARTDATEが終了日よりも大きければ、私はのCustomValidatorを作成したので、確実に(そしてユーザーのために印刷)する必要がありますが、
public class CustomIsValidDate : ValidationAttribute
{
public DateTime? StartDate { get; set; }
public DateTime? EndDate { get; set; }
public CustomIsValidDate(DateTime? startDate, DateTime? endDate)
{
StartDate = startDate;
EndDate = endDate;
}
public override bool IsValid(object value)
{
if (StartDate == null || EndDate == null)
return true;
if (EndDate > StartDate)
return true;
return false;
}
}
をいけない仕事}
[CustomIsValidDate(DateOut.GetDateTime,DateIn.GetDateTime,ErrorMessage = "Returning date must be higher than ingoing date!")]
public DateTimeViewModelNullable DateIn { get; set; }
非静的フィールド、メソッド、またはプロパティに参照が必要です
私はかなり従いません。あなたは何を意味するのか? – Mech0z