In my ASP.NET MVC API application, I can return a helpful ErrorResponse
if a few of my Required
fields are missing:
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
-
"Message": "The request is invalid.",
"ModelState": {
"myModel.FooA": [
"The FooA is required."
],
"myModel.FooC": [
"The FooC property is required."
],
"myModel.FooD": [
"The FooD property is required."
]
}
However as this answer confirms, a NULL model will validate. As I don't allow this, how can I return an equally helpful error response stating all the values that are required? I know that I can manually add a ModelError for each property, but I suspect there may be a way that CreateErrorResponse
can do this for me.