c# - SelectList ToShortDateString viewbag -


my project mvc5, using ef 6.1; generate dropdownlist using following:

model:

public partial class logbook {     public string id { get; set; }     public string thename { get; set; }     public system.datetime day { get; set; } } 

controller:

var list = db.logbook.where(i => i.thename == xxx).orderbydescending(x => x.day).tolist(); viewbag.logbooks = new selectlist(list, "id", "day"); 

view:

@html.dropdownlist("logbookdate", viewbag.logbooks  selectlist)  

the result shows:

11/11/2014 12:00 

how can display date?

try this:

var list = db.logbook.where(i => i.thename == xxx).select(d=> new {id= d.thename, day = d.day.toshortdatestring()).orderbydescending(x => x.day).tolist();  viewbag.logbooks = new selectlist(list, "id", "day"); 

haven't done practical should work.

edit:

ienumerable<selectlistitem> selectlist =      c in db.logbook     c.thename equals xxx     select new selectlistitem     {         text = c.id,         value = c.day.toshortdatestring()     }; 

then bind dropdonwlist on front.

you can give try. have not checked syntax. hope fine.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -