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 334 times
1
Muhammad Faisal
- 95
- 12
-
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
- 73,987
- 13
- 62
- 116