Skip to content

Optional [FromBody] Model Binding #6878

Closed
@douglasg14b

Description

@douglasg14b

Is your feature request related to a problem? Please describe.

I am trying to use optional [FromBody] model binding on a per-endpoint basis.
Example:

        [HttpPost]
        public IActionResult Post([FromBody]SomeClass request = null)
        {
            return Ok();
        }

An empty request body results in the following being returned:

{
  "": [
    "A non-empty request body is required."
  ]
}

Describe the solution you'd like

For properties that have default value ie [FromBody] bool expandRelations = true to not be required in the body of the request.

Additional context

Similar issue here: aspnet/Mvc#6920

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesenhancementThis issue represents an ask for new feature or an enhancement to an existing onehelp wantedUp for grabs. We would accept a PR to help resolve this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions