I have a Blazor server application using .Net 8.
In a Razor component I have an EditForm, where I set the Model to a variable like this:
<EditForm Model="@ClientPayeeSearchModel"
The ClientPayeeSearchModel variable points to an instance of the ClientPayeeSearch class, where I have a nullable int property defined like this:
public int? PayeeID { get; set; }
In my EditForm I am rendering this nullable int like so, using the built-in InputNumber component:
<InputNumber id="payeeID" class="form-control" @bind-Value="ClientPayeeSearchModel.PayeeID" />
My problem is, when I leave this input empty and submit the form, I get the validation error message
The value ” is not valid for ‘PayeeID’.
Obviously Blazor thinks I’m trying to set this nullable int to an empty string. I expected Blazor to realize that I simply want to leave it null.
How does one render a nullable int in a Blazor EditForm so that it participates in validation properly?