I am trying to display a datetime field retrieved froma database in my razor file with the following:
@Html.EditorFor(model => model.RequestDate);
I know with 100% certainty the RequestDate is not null, as I examined the model that was passed in the view, and it was the date from the database. However, the datetime textbox still displays "mm/dd/yyyy". I don't know why it is not display the date. Any ideas? Thank you.
Here is my model:
[Display(Name = "Time")]
[DataType(DataType.Date)]
public DateTime RequestDate { get; set; }
EDIT:
[HttpGet]
public ActionResult DispatchResponseIndex()
{
DispatchResponseModel model = new DispatchResponseModel();
//if the users session id isnt null then we know they have data related to this form
object UserID = Session["TestID"];
if (UserID == null)
{
return View(model); //default view
}
else
{
UserID = Session["TestID"];
}
LoadDB(model, (Guid)UserID);
//looking at the model here the RequestDate has a valid date of //{5/24/2013 12:00:00 AM}
return View(model);
}
EDIT 2:
If I use @Html.TextBox("asdasd",Model.RequestDate); Then it will display the saved date in string format, but I need to use the built in date editor for the text box.
This does seem to cause a lot of confusion and it annoyed me!
If you use DataType.Date
you need to set it like this:
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
Chrome's date picker uses the local computer's short date format. Even setting the lang
tag is ignored; here is an example using Chrome and <html lang="en-GB">
:
Chrome's date picker also uses the local computer's locale. On page load, the date will be populated (if set) and the user can select a new date:
Note: If you change the computer's locale you must restart Chrome completely to see the locale change.
FINAL
I'm an idiot. I had no idea Chrome had a date picker that it added. I thought it was something built into MVC. I need to use an actual jquery date picker. Thanks everyone for all the info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With