Reputation: 2711
I have two dropdownlists in my project, one list with strings and one list with datetimes. My controller checks the first list (of strings) like this:
if (string.IsNullOrEmpty(animals))
return View(person);
else
return View(person.Where(d => d.animals == animals));
The same code wont work with the lists of datetimes because I get an error saying that a datetime cant be null. Any ideas of how i can make something similar with a list of datetimes?
Upvotes: 0
Views: 162
Reputation: 31636
Have the view handle the null situation and the situation were this is a default min value in the list:
return View( ((MyListOfDates != null) && (MyListOfDates.Any()) ?
MyListOfDates.FirstOrDefault(dtTime=> dtTime != DateTime.MinValue) :
DateTime.MinValue);
Upvotes: 2