In my model I have an nullable int.
In the view I have an input of type 'number'.
The problem is that the user could possibly input a number larger than the maximum possible integer value, which results in the following error:
The value [value] is not valid for [field]
I want to change this message, and putting a [Range(...)] validation on the attribute does not help, as non of my validations are being called, because the framework cannot parse the value to an int.
--------- EDIT ---------
My validations perform normally at normal input as shown here:
What I mean about my validations not being called is that I've read that the if the framework fails to parse the value to an int (because the value exceeds the max value of an integer), it ignores any further "unnecessary" validation.
Therefore my Range validation is ignored, as shown here:
I've tried creating a custom ValidationAttribute, but that has the same behaviour (Being called correctly at normal integer input, but is ignored at overflowing integer input)
--------- /EDIT ---------
All the solutions I have seen, proposes binding a custom resource file, in which I could override the default message for invalid values.
But I want to be able to specify a custom message at each attribute in case of an invalid value.
I thought about using strings instead of ints, and creating a custom ValidationAttribute which tries to parse it to an int.
Are there any alternatives?
// EDIT: I could avoid this problem (to some degree) by having client-side validation - But I want to know if it is possible from the server-side, in case of someone editing the html and forcing a higher value


9999999999999the range validation message is displayed as soon as you tab out of the control. - user3559349DefaultModelBindertries to set the value to9999999999999which it cant, so the value is not valid error is added toModelState(the 'Range' condition is not even checked because there is no point) - user3559349