1
I have a Viewbag returning two dates in a Dropdown, but they are returning with the same format that were saved in the database( MM/dd/yyy HH:mm:ss). I need them to return in the pattern(dd/MM/yyyy).
My Viewbag is like this:
ViewBag.Ferias = funcionarioFeriasRepository.Lista.Where(r => r.CdMatricula == matricula && r.SqContrato == contrato && r.DtInicioConcessao != null)
.Select(x => x.DtInicioPeriodo + " à " + x.DtFimPeriodo);
And in my view, I call her that way:
@Html.DropDownList("Ferias", new SelectList(ViewBag.Ferias, "Ferias"))
The result is this:
Jun 22 2010 12:00AM to Feb 19 2014 12:00AM
I have tried, but I get the following error: "No Overload for method 'Tostring' takes 1 Arguments"
– Randrade
Try calling a
.ToList()
, see if this works:ViewBag.Ferias = funcionarioFeriasRepository.Lista.Where(r => r.CdMatricula == matricula && r.SqContrato == contrato && r.DtInicioConcessao != null).ToList().Select(x => x.DtInicioPeriodo.ToString("dd/MM/yyyy") + " à " + x.DtFimPeriodo.ToString("dd/MM/yyyy"));
– iuristona
I get the same mistake with . Tolist()
– Randrade
Um, the guy
DtInicioPeriodo
isDateTime
orstring
?– iuristona
the two fields are of type Datetime
– Randrade
Apparently the guy isn’t
DateTime
, maybeDateTime?
(nullable)?. Try now, as I changed the answer.– iuristona
I get this error now: does not contain a Definition for value and no Extension method value Accepting a first argument of type could be found(are you Missing using Directive or an Assembly Reference)
– Randrade
Data is Datetime? (nullable) yes
– Randrade
I changed the answer again, see if that’s it.
– iuristona
I continue with the same error: does not contain a Definition for value and no Extension method value Accepting a first argument of type could be found(are you Missing using Directive or an Assembly Reference)
– Randrade