3

This syntax below does not work with MVC4 and the bootstrap date text input. It works fine with a normal text box. Please advise, thank you.

<input type="date" id="PickupDate" name="PickupDate" class="form-control" value="@Model.PickupDate.ToString("d")"> 
2
  • I am trying to populate the bootstrap date text input box with the date from the database, but nothing appears in the input box with the syntax above. How to you populate the date text box with the date from sql server dateabase? Commented Aug 12, 2013 at 0:18
  • Just fyi, I don't think Bootstrap has a specific date input. What you are seeing is the HTML 5 date input type. See here for more: diveintohtml5.info/forms.html#type-date Commented Aug 12, 2013 at 3:51

1 Answer 1

1

Assuming that PickupDate is a DateTime object, try using this to format it:

value="@Model.PickupDate.ToString("yyyy-MM-d")" 

Also, double check that @Model.PickUpDate actually has a valid value.

EDIT:

Try using 2 d's :

value="@Model.PickupDate.ToString("yyyy-MM-dd")" 
Sign up to request clarification or add additional context in comments.

9 Comments

@Model.PickUpDate definitely has a date value, if I change the text box back to a normal one it displays the date fine. But as a bootstrap 3.0 input type="date" class="form-control" I see no way of setting the value property, even if i just try to do something like value="test123" the input date object still comes up empty in the browser. it's like that object would use some other property rather than value to set it's display value?
the bootstrap input type="date" class="form-control" control is fantastic for getting the date from the user on an add new page, but I can't figure out how to display the date back from the database on an edit page with MVC.
What I am saying is to give the date to the date input in a different format. The date needs to be in a particular format. Here is a CodePen to illustrate what I mean. codepen.io/simoncowie/pen/aLKJg
I understand what you are saying, and I believe you are correct. But, it doesn't work in MVC4.
both of these work: <input type="text" id="PickupDate" name="PickupDate" class="form-control" value="@Model.PickupDate.ToString("d")"> AND <input type="text" id="PickupDate" name="PickupDate" class="form-control" value="@Model.PickupDate.ToString("yyyy-MM-d")"> BUT if you change the type to type=date you get nothing in MVC4. This does not work: <input type="date" id="PickupDate" name="PickupDate" class="form-control" value="@Model.PickupDate.ToString("yyyy-MM-d")">
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.