Your RevisionDate
property is by default set to DateTime.MinValue
which is 01/01/0001 ( all DateTime
properties behave like that). This is why the Kendo UI DatePicker shows it like that. The solution is to make the property a nullable DateTime
(DateTime?
) whose default value is null
.
Default Empty value in Kendo DatePicker
-
22-09-2022 - |
Вопрос
I need the default value of datetime picker to be empty.
@(Html.Kendo().DatePickerFor(model => model.RevisionDate)
.Name("RevisionDate")
)
"RevisionDate" is a datetime property in a asp.net mvc model.
how it's currently being displayed
and i need to display it as below
Решение
Другие советы
If you don't want to make the property nullable, you can also do it like this:
@(Html.Kendo().DatePickerFor(m => m.Property).HtmlAttributes(new { value = "" }))
I had the same problem with a ComboBoxFor ComboBoxFor(m => m.LocationId).Value(Model.LocationId == 0 ? string.Empty : Model.LocationId.ToString())
.
But I see that this approach doesn't work on the DatePickerFor(It could be a bug).
A workaround could be made in JS if($('#RevisionDate ').val() == "1/1/0001") { $('#RevisionDate ').val("") }
but I would recommand Atanas's approach with a nullable field.
Не связан с StackOverflow