How do you get a list of all ModelState error messages? I found this code to get all the keys: ( Returning a list of keys with ModelState errors)
var errorK
Take a look at System.Web.Http.Results.OkNegotiatedContentResult.
It converts whatever you throw into it to JSON.
So I did this
var errorList = ModelState.ToDictionary(kvp => kvp.Key.Replace("model.", ""), kvp => kvp.Value.Errors[0].ErrorMessage);
return Ok(errorList);
This resulted in:
{
"Email":"The Email field is not a valid e-mail address."
}
I am yet to check what happens when there is more than one error for each field but the point is the OkNegoriatedContentResult is brilliant!
Got the linq/lambda idea from @SLaks