Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC DateTime Textbox Formatting Issue

Tags:

I would like to do something like

model.PickupDate.ToString("d")

But MVC4 is not liking that very much. PickupDate is a DateTime field and I would like to strip off the time portion when displayed in the view, while keeping the new { id = "date1" } code which binds the TextBoxFor to the javasript datepicker. How can I display the Date portion only in this instance?

@Html.TextBoxFor(model => model.PickupDate, new { id = "date1" })
like image 432
Austin Harris Avatar asked Jul 25 '13 06:07

Austin Harris


1 Answers

this is how I would do this. Hope it helps

 @Html.TextBoxFor(m => m.MyDateTime, new { Value = Model.MyDateTime.ToString("MM-dd-yyyy"), id = "MySuperCoolId"});

or in your case

@Html.TextBoxFor(m => m.PickupDated, new { Value = Model.PickupDate.ToString("d"), id = "date1"});
like image 152
Kenneth Garza Avatar answered Sep 24 '22 11:09

Kenneth Garza