Skip to content

In Minimal API, there are binding issues when using FromForm. #60556

Open
@chipeng1023

Description

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

public class Test
{
public int? ID { get; set; }
public string Code { get; set; }
[Required]
public string Name { get; set; }
public DateOnly? Birthday { get; set; }
public DateTime? AddTime { get; set; }
public IFormFile File { get; set; }
public IFormFile[] Files { get; set; }
public static ValueTask BindAsync(HttpContext context) { return ValueTask.FromResult(new Test()); }
}

public static IResult SubmitForm([FromForm] Test test, [NotNull] string flag)
{
//todo
}

1、An empty string cannot be bind to a value type property.
Image
Microsoft.AspNetCore.Http.BadHttpRequestException: The value '' is not valid for 'Birthday'.
at Microsoft.AspNetCore.Http.RequestDelegateFactory.Log.FormDataMappingFailed(HttpContext httpContext, String parameterTypeName, String parameterName, FormDataMappingException exception, Boolean shouldThrow)
at lambda_method78(Closure, Object, HttpContext, Object)
at Microsoft.AspNetCore.Http.RequestDelegateFactory.<>c__DisplayClass103_2.<b__2>d.MoveNext()`

2、IFormFile[] Files is null
Image
Image

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

net9.0

Anything else?

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Needs: Attention 👋This issue needs the attention of a contributor, typically because the OP has provided an update.area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etc

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions