Mateycho
Member
- Joined
- Mar 12, 2024
- Messages
- 10
- Programming Experience
- 3-5
Hi guys, I am really struggling the previous week to find out why is there a difference when I pass the error property through the constructor of my custom validation attribute or when I pass it explicitly. I have been looking through the source code so much that my eyes started hurting, hah. When I pass it through the constructor on the client side I get the following error: [de-CH: isValidEmail], which might be since we have many languages on our application, but when I pass the same string explicitly it returns the correctly formated error.
Can someone explain why we have this behavior? Also, what would be the best practice with validation attributes to override bool isValid and FormatErrorMessage methods or something other, since I don't want to pass the ErrorMessage in the ViewModel to pollute the code there? Thanks!
Currently, I am doing things like in the picture and it works fine, but I am just speechless why doesn't the error message work when passed from the constructor? Could it be because it expects some formating, or culture definition before passing and the ErrorMessage explicitly is like the default one, which doesn't need such modifications to be displayed correctly? Can someone help?
Can someone explain why we have this behavior? Also, what would be the best practice with validation attributes to override bool isValid and FormatErrorMessage methods or something other, since I don't want to pass the ErrorMessage in the ViewModel to pollute the code there? Thanks!
Currently, I am doing things like in the picture and it works fine, but I am just speechless why doesn't the error message work when passed from the constructor? Could it be because it expects some formating, or culture definition before passing and the ErrorMessage explicitly is like the default one, which doesn't need such modifications to be displayed correctly? Can someone help?