How do I prevent the time from showing up when using the jQuery
.datepicker()
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
[DisplayName("Expiration Date")]
public string ExpirationDate { get; set; }
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
[DisplayName("Date Taken")]
public string DateTaken { get; set; }
@Html.EditorFor
@Html.EditorFor(model => model.DateTaken)
@Html.TextBoxFor(m => m.DateTaken, new { id = "dtkn" })
datepicker
<script>
$(function () {
$("#dtkn").datepicker('setDate');
$("#exp").datepicker('setDate');
});
$.datepicker.setDefaults({
buttonImageOnly: true,
buttonImage: '<%=Url.Content("~/Content/images/magnify.gif") %>',
defaultDate: -1,
gotoCurrent: true,
prevText: "<< Prev",
nextText: "Next >>"
});
</script>
$("#dtkn").datepicker({ dateFormat: 'dd-mm-yy' }).val();
$("#dtkn").datepicker({ dateFormat: 'yy-mm-dd' });
$("#dtkn").datepicker('getDate').format('yyyyMMdd');
$("#dtkn").datepicker('getDate').datepicker('dd/mm/yy');
$('#dtkn').datepicker('option', { dateFormat: 'd MM y' });
Uncaught TypeError: Cannot call method 'datepicker' of null
By using @Html.TextBox
as opposed to @Html.TextBoxFor
I was able to find an overload that works.
@Html.TextBox("DateTaken", Model.DateTaken.ToString("MM/dd/yyyy"), new { id = "dtkn" })