Possible Duplicate:
MVC3 custom validation: compare two dates
I am trying to make a validation for my date so that start date must be < than end date.If end date is before start date tha n i throw an exception .How can i show this exception on my screen so when i press search buton and the dates are wrong a message to appear?
public ActionResult SearchFree(DateTime? StartDate, DateTime? EndDate)
{
if (StartDate.HasValue && EndDate.HasValue)
{
DateTime d1 = StartDate.Value;
DateTime d2 = EndDate.Value;
TimeSpan span = d2 - d1;
if (span.Days <= 0)
{
throw new ArgumentOutOfRangeException("start date must be before end date");
}
try
{
DBContext.Current.Open();
var model = Reservation.SelectFreeRooms(StartDate, EndDate);
DBContext.Current.Close();
return View(model);
}
catch (ArgumentException ae)
{
throw ae;
}
}
return View(new List<dynamic>());
}