I'm building an ASP.NET Web API 2. I'm serializing the JSON data to my model, which uses DataAnnotations, more specifically the Range and RegularExpression.
Everything works great, however, when the ModelState is not valid, I would like to be able to return all the invalid values back to the client.
Example:
public class Book {
...(fields removed for brevity)
[Range(0, 100)]
public int? Pages { get; set; }
}
Currently when the client sends a message with an invalid range(-1 for example), the returned message is: "The field Pages must be between 0 and 100."
I would like to return something like this: "The field Pages must be between 0 and 100. Current Value is -1."