Simpler Custom Validation (Server-Side)

Feb 3, 2010 at 2:23 PM
Edited Feb 3, 2010 at 2:24 PM

I find it more than a little unweildy to have to define a whole nother class when I want to add a fairly straight forward server-side validation rule.

 

I'd ideally prefer to be able to define a method at the model layer that does the validation.

 

Any idea how to do this

[ValidateBookingDate]
public DateTime BookingDate
{
    get;
    set;
}

public
static IEnumerable<ErrorInfo> ValidateBookingDate(Object bookingDate ) { if ((bookingDate.DayOfWeek == DayOfWeek.Saturday) || (ookingDate.DayOfWeek == DayOfWeek.Sunday)) yield return new ErrorInfo("BookingDate", "Bookings cannot be placed on weekends");
}