I’m using ASP.NET Core Minimal API. I have an endpoint where I want to receive an IFormFile along with a Dictionary<string, string> property in the same request. I set the Accepts<TestDictionaryRequest>("multipart/form-data") and use [FromForm] on the handler parameter. Uploading the file works correctly, but the TestDictionary property is always null, even when I set values in the Swagger UI.
Here is the code:
public class TestDictionaryRequest
{
public Dictionary<string, string> TestDictionary { get; set; }
public IFormFile TestFile { get; set; }
}
public class TestDictionaryEndpoint : IEndpoint
{
public void MapEndpoint(IEndpointRouteBuilder app)
{
app.MapPost("test/dictionary", Handler)
.DisableAntiforgery()
.WithTags("Test")
.Accepts<TestDictionaryRequest>("multipart/form-data");
}
public static IResult Handler([FromForm] TestDictionaryRequest request)
{
return Results.Ok(new
{
Dictionary = request.TestDictionary,
Count = request.TestDictionary?.Count ?? 0,
IsNull = request.TestDictionary == null
});
}
}
What additional steps or configuration are needed so that the Dictionary<string, string> TestDictionary is bound correctly (not null) when using multipart/form-data with IFormFile in a Minimal API endpoint?


