ValidationAttribute.FormatErrorMessage throwing Input string was not in a correct format error

124 Views Asked by At

I have written a custom attribute. In the error message I have special characters. due to these special characters, ValidationAttribute.FormatErrorMessage(GetDisplayName()) throwing Input string was not in a correct format error.

My error message is @"Your characters should be in: ^_{}~".

How can I fix this issue?

1

There are 1 best solutions below

0
Samarth Jaiswal On BEST ANSWER

The error is because of {}. It has special meaning in c#. So you have to use escape character for that. ex: (ErrorMessage = "Your characters should be in: !#$%&()*+,-./:;<=>?@[]^_{{|}}~"

So for escaping {, you have to use double {.