C
C#2y ago
Simo

❔ ModelState.IsValid

do I need to call this explicitly myself or does the framework call this when using webAPI? I would assume that its called automatically but its still possible for the JSON to end up de-serialized but still not be valid?
3 Replies
Saber
Saber2y ago
controllers marked with [ApiController] automatically check this and return a bad request
Simo
SimoOP2y ago
thank you! that clears it up that explains this type of response then:
{
"errors": {
"EmailAddress": [
"The EmailAddress field is required."
]
},
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"traceId": "00-eba25af423d72cafb9cd245658d426c4-18ed1876309cd757-01"
}
{
"errors": {
"EmailAddress": [
"The EmailAddress field is required."
]
},
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"traceId": "00-eba25af423d72cafb9cd245658d426c4-18ed1876309cd757-01"
}
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server