we can validate mandatory fields by using Required attribute but what about model what if we pass empty post body ? i have check the controller i am getting null object and ModelState.IsValid
is true on action executing even though there are required fields in model. is there any way to validate null/empty body ?
Asked
Active
Viewed 781 times
1

Muhammad Faisal
- 155
- 2
- 13
-
1Possible duplicate of https://stackoverflow.com/questions/19851352/modelstate-is-valid-with-null-model – allan May 18 '20 at 10:42
1 Answers
1
You can as well check explicitly
if (inputModel == null) {
return BadRequest();
}

Rahul
- 76,197
- 13
- 71
- 125