This is a migrated thread and some comments may be shown as answers.

Binding to nullable DateTime

8 Answers 3237 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 1
Nick asked on 10 Jun 2019, 04:33 PM

Hi,

Is there any way of binding to a nullable DateTime or is there a recommended approach for handling null/empty values. I think this question could apply to any of the controls that bind to a struct or an in-built type like Int/Decimal.

Thanks,

Nick.

 

8 Answers, 1 is accepted

Sort by
0
Nick
Top achievements
Rank 1
answered on 11 Jun 2019, 10:20 AM
I'm not sure if it helps, but there's a discussion in the Asp.Net core issues page about binding to nullable types: https://github.com/aspnet/AspNetCore/issues/5541
0
Marin Bratanov
Telerik team
answered on 11 Jun 2019, 11:52 AM
Hi Nick,

Nullable DateTime is still not supported and you can track this feature in the following page: https://feedback.telerik.com/blazor/1410422-binding-to-nullable-value.


Regards,
Marin Bratanov
Progress Telerik UI for Blazor
0
Nick
Top achievements
Rank 1
answered on 11 Jun 2019, 12:28 PM
Thanks Marin, sorry I should have looked first.
0
Marin Bratanov
Telerik team
answered on 11 Jun 2019, 01:17 PM
No worries, Nick, that's why I'm here :)

I would personally have expected that to work too, in your place. We simply haven't gotten around to clearing up all of those things, with all the changes and new things that are happening. It's early days for Blazor, and even more so for component suites on it.

--Marin

0
Sean
Top achievements
Rank 1
answered on 28 Aug 2019, 06:25 PM
Hi. This shows as completed in the top left, but it doesn't work yet. Any further progress?
0
Marin Bratanov
Telerik team
answered on 29 Aug 2019, 08:29 AM

Hello Sean,

What version of Telerik UI for Blazor are you running? Can you confirm you are on 1.6.0 and that you have .NET Core 3 Preview 8 installed?

I just tested the following code and it seems to work fine for me (I am also attaching a video of my test at the end of this post):

@using Telerik.Blazor.Components.DatePicker
@using Telerik.Blazor.Components.DateInput

<TelerikDatePicker @bind-Value="theDate"></TelerikDatePicker>
<br />
The selected date is: @theDate
<br />
<TelerikDateInput @bind-Value="@StartDate" Format="MM/dd/yyyy HH:mm:ss"></TelerikDateInput>
<br />
The date input date is: @StartDate

@code {
    DateTime? theDate;
    DateTime? StartDate { get; set; } = new DateTime(2020, 1, 1);
}

 

Regards,
Marin Bratanov
Progress Telerik

 UI for Blazor
0
Nic
Top achievements
Rank 2
answered on 09 Dec 2020, 09:33 PM

Hello... 

Is the DatePicker having issues with nullable date values ? 

when a value is null we get the default value of 1/1/0001

how do we get around this issue .. we still want to preserve the null value..  have you guys fixed this yet? 

This post is dated from Jun 2019.. so.. i hope there is an alternative solution a year and a half later.. 

Please advice.. Thanks !!!

0
Svetoslav Dimitrov
Telerik team
answered on 11 Dec 2020, 09:30 AM

Hello,

The DatePicker should not have an issue with the nullable DateTime type. Below, I have prepared two examples of the DatPicker using both nullable and non-nullable DateTime objects. 

<h3>Nullable DateTimePicker</h3>
<TelerikDatePicker @bind-Value="@HireDate"></TelerikDatePicker>

<h3>Non-nullable DateTimePicker</h3>
<TelerikDatePicker @bind-Value="@VacationDate"></TelerikDatePicker>

@code {
    public DateTime? HireDate { get; set; } //nullable DateTime - default value null
    public DateTime VacationDate { get; set; } //non-nullable - default value 1/1/0001
}

Regards,
Svetoslav Dimitrov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
DatePicker
Asked by
Nick
Top achievements
Rank 1
Answers by
Nick
Top achievements
Rank 1
Marin Bratanov
Telerik team
Sean
Top achievements
Rank 1
Nic
Top achievements
Rank 2
Svetoslav Dimitrov
Telerik team
Share this question
or