Skip to content

Commit 113ed43

Browse files
authored
WN .NET 10 Prev2: Prep: Move Min API empty string section to include (#34989)
Prep only, moving to include.
1 parent 74dc6cb commit 113ed43

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
### Treating empty string in form post as null for nullable value types
2+
3+
When using the `[FromForm]` attribute with a complex object in minimal APIs, empty string values in a form post are now converted to null rather than causing a parse failure. This behavior matches the processing logic for form posts not associated with complex object's in minimal APIs.
4+
5+
```csharp
6+
using Microsoft.AspNetCore.Http;
7+
8+
var builder = WebApplication.CreateBuilder(args);
9+
10+
var app = builder.Build();
11+
12+
app.MapPost("/todo", ([FromForm] Todo todo) => TypedResults.Ok(todo));
13+
14+
app.Run();
15+
16+
public class Todo
17+
{
18+
public int Id { get; set; }
19+
public DateOnly? DueDate { get; set; } // Empty strings map to `null`
20+
public string Title { get; set; }
21+
public bool IsCompleted { get; set; }
22+
}
23+
```
24+
25+
Thanks to @nvmkpk for contributing this change!

0 commit comments

Comments
 (0)