Search code examples
c#blazor.net-8.0fluent-ui

Fluent UI Blazor datepicker


Im trying to make a dialog where i can change a persons name and birthday, the name is working as intended i only have an issue with the birthday which is using a FluentDatePicker.

This is my dialog component:

@implements IDialogContentComponent<FleuntBlazorWebApp.UI.Pages.People.Person>

<FluentDialogBody>
    <FluentTextField Label="Name:" @bind-Value="@Content.Name"/>
    <FluentDatePicker Label="Birthday" @bind-Value="@(Content.BirthDate)" />
</FluentDialogBody>

@code{
    [Parameter]
    public FleuntBlazorWebApp.UI.Pages.People.Person Content { get; set; } = default!;

    [CascadingParameter]
    public FluentDialog Dialog { get; set; }

    private async Task SaveAsync()
    {
        await Dialog.CloseAsync(Content);
    }

    private async Task CancelAsync()
    {
        await Dialog.CancelAsync();
    }
}

and this is the person object:

public record Person
{
    public int PersonId { get; set; }
    public string Name { get; set; }
    public DateTime BirthDate { get; set; }
}

and this is the error im getting:

cannot convert from 'Microsoft.AspNetCore.Components.EventCallback<System.DateTime>' to 'Microsoft.AspNetCore.Components.EventCallback'

thanks in advance,


Solution

  • public DateTime? BirthDate { get; set; }
    

    the FluentDatePicker expects a nullable DateTime (DateTime?), ensure that your BirthDate property is nullable.