dotnet / dotnet/aspnetcore

Missing required value for constructor parameter

Open
#56,234 5 comments 3 reactions 0 assignees View on GitHub
area-minimal
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [X] 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> 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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.