Search code examples
c#blazornullablemudblazormudtextfield

Validation error occurs when binding DateTime? with MudBlazor's MudTextField


I set MudTextField's InputType to DateTimeLocal and bound it to the DateTime? member, but a validation error occurs in Visual Studio 2019, using .NET 5.0 and MudBlazor 5.2.5.

<MudTextField Format="s" InputType="InputType.DateTimeLocal" @bind-Value="testdate" />

@code {
    private DateTime? testdate { get; set; }
}

Form error screenshot:

form error

As mentioned above, I tried to isolate the problem by simplifying the code as much as possible, but I can't dig any further.

I searched as much as I could, but I couldn't find a topic with the same problem.

I would like advice from someone who knows.


Solution

  • Use: T="DateTime?"

    <MudTextField T="DateTime?" Format="s" InputType="InputType.DateTimeLocal" @bind-Value="testdate" />
    
    @code {
        private DateTime? testdate { get; set; }
    }