Reputation: 10478
Okay I've tried pretty much everything in the other answers I've seen here.
I am using jQueryUI datepicker on my MVC form, which also uses knockout. I want to only display the date, not the time.
Heres my markup:
<div class="editor-label">
@Html.LabelFor(model => model.StartDate.Date)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.StartDate.Date, new { @class = "date-picker", id = "StartDate", data_bind = "value: StartDate" })
@Html.ValidationMessageFor(model => model.StartDate.Date)
</div>
And then in my model I've set the datatype:
[Required]
[DataType(DataType.Date)]
public DateTime StartDate { get; set; }
And in the datepicker jquery in document.ready I have the format set:
$(".date-picker").datepicker({ dateFormat: "dd/mm/yy" });
Yet when the page loads, it still displays the time (12:00 AM) along with the date. How can I get rid of this??
Upvotes: 0
Views: 617
Reputation: 3800
Try adding this afterwards:
$(".date-picker").datepicker("setDate", new Date("@Model.StartDate"));
Upvotes: 0
Reputation: 36
Try setting the type of textbox to date. Using the attributes will only work with the editor not textbox.
Upvotes: 1