Let's say there's a PUT request coming from my client, I want to process this data. with the FromBody
attribute I can get the bound data. But when there's no data bound to my [FromBody] object I want to send 400 to my client. Because if I don't, I will update my database with an object who's members are null/default for no reason. How do I get around this in .NET 5?
an example function definition would be:
public async Task<IActionResult> PutAsync(long id, [FromBody] PersonUpdateDto personUpdateModel)
public class PersonUpdateDto {
public string Name {get; set;}
public string Surname {get; set;}
}
Again, I want to return 400 to my client if all the members in personUpdateModel
is null.(which means no bind operation happened)