Skip to content

Missing required value for constructor parameter #56234

Open
@andrew-vdb

Description

@andrew-vdb

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

How difficult can this be

Checkbox in html form when its not true, simply not to submit the value in the property

 public record PostParameter([Required][EmailAddress] string Email, [Required][MinLength(8)] string Password, string? RememberMe = "unchecked");

 internal static async Task<Results<RedirectHttpResult, BadRequest>> Post(HttpContext httpContext, [FromForm] PostParameter parameter)

PostParameter has optional parameter but that optional parameter is not respected

BadHttpRequestException: Missing required value for constructor parameter 'RememberMe'.

Microsoft.AspNetCore.Http.RequestDelegateFactory+Log.FormDataMappingFailed(HttpContext httpContext, string parameterTypeName, string parameterName, FormDataMappingException exception, bool shouldThrow)

Expected Behavior

should simply accept (no exception) when client not sending "RememberMe" in the payload

Steps To Reproduce

No response

Exceptions (if any)

FormDataMappingException

.NET Version

8

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etc

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions