Minimal API : Converting empty string to Nullable (ex: int?) with [FromForm] binding #55202
Open
1 task done
Labels
area-blazor
Includes: Blazor, Razor Components
area-minimal
Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc
feature-blazor-form-validation
This issue is related to forms validation in Blazor
Milestone
Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
From a Minimal API project
With the HTML form
And Mapping
app.MapPost("/SomeUrl", ([FromForm] SomeModel theInputModel) => Results.Ok());
And Model
If I enter a number in "SomeProp" input field, it works ok.
But if I leave "SomeProp" input field empty and the submit the form, I get the exception:
That is because the request sent to the server when posting the form is a POST with content :
someProp=
The only workaroung I found is using a string instead of int? and then convert string to int? by myself which is not the best solution.
Describe the solution you'd like
When binding [FromForm], I beleive that Minimal API should convert empty string to null when converting to a Nullable type (ex int?).
Or at least give any option to do so.
Additional context
No response
The text was updated successfully, but these errors were encountered: