I have a class which is a parameter of a method in controller which has a required property (mark as [Required]).
When I pass a null value to that property I get a message saying:
"errors": {
"testNumber": [
"Error converting value {null} to type 'System.Int32'. Path 'testNumber', line 21, position 15."
]
}
Similarly, when I pass a null value to that property I get a message saying:
"errors": {
"testNumber": [
"JSON integer 999999999999999999999999999 is too large or small for an Int32. Path 'testNumber', line 21, position 38."
]
}
I want to customize the friendly messages saying:
"errors": {
"testNumber": [
"null is not a valid value for TestNumber."
]
or
"errors": {
"testNumber": [
"999999999999999999999999999 is not a valid value for TestNumber."
]
}
My TestClass is very simple:
public class TestClass
{
[Required]
public int TestNumber{ get; set; }
}
I have a look at some posts they suggest to use:
[Required(ErrorMessage="<your value> is not a valid value for TestNumber.")]
public int TestNumber{ get; set; }
But by doing this way, I can't get the original value sent from client. So is this possible to customize the messages like above?
Thank you.