Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Validation error is not thrown when a complex type property with required and from body attributes has null value #2219

Closed
@kirthik

Description

@kirthik

Assume a model like this

public class Customer
{
        public int Id {get; set;}
        [Required]
        [FromBody]
        public Address Address {get; set;}
}

public class Address
{
     public string Street {get; set;}
}

And I have an action

public IActionResult CreateCustomer(int id)
{
     var c = GetCustomer(id);
     TryUpdateModel(c)
     if (!ModelState.IsValid)
    { ....}
}

If I call CreateCustomer with empty json in the body, expectation is I will get a model state error saying Address is required but ModelState does not contain that error.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions