In controller I had created a DropDown list for Date, now I need to filter dates and to take dates >= from Today.
here is code of DropDown list which I need to filter like this:
ViewBag.Datum = new SelectList(db.tbl_relacii, "DatumR", "DatumR").Where("DatumR" >= DateTime.Now.Date());
How to filter DropDown list? Also in database table I put like Date format, but when I take data in DropDown list without .Where I see included Time like this 23.03.2017 00:00:00
if you are trying to filter the result before creating the dropdownlist items i.e. SelecList
then you would need to filter them first and then pass the filtered list to SelectList
's constructor:
var date = DateTime.Now.Date; // as Ef wouldnl't be able to translate to sql
if we add it within Where directly
ViewBag.Datum = new SelectList(db.tbl_relacii
.Where(x=>x.DatumR >= date),
"DatumR",
"DatumR");