After spending some more time thinking about the problem, I managed to come up with something that seems to work. I don't really love the solution, however: foreach (ValidationAttribute validationAttribute in attributes. Where(x => x is ValidationAttribute)) { if (String.
IsNullOrEmpty(validationAttribute. ErrorMessage)) { validationAttribute. ErrorMessage = validationAttribute.
FormatErrorMessage(formattedPropertyName); } } This code runs at the same time as the code in the question (as part of the CreateMetadata method in the custom metadata provider). It works in all of the cases I've tested, but it's not really providing the metadata to the validation provider so much as formatting the error string using a Pascal cased version of the property name. This works with the way that most of the normal validation messages are setup.
The fact that it is explicitly setting the error message on the validation attributes doesn't seem correct I don't known that this is would work as a global solution, however. This solution "works", but I hope that a better solution is available.
After spending some more time thinking about the problem, I managed to come up with something that seems to work. I don't really love the solution, however: foreach (ValidationAttribute validationAttribute in attributes. Where(x => x is ValidationAttribute)) { if (String.
IsNullOrEmpty(validationAttribute. ErrorMessage)) { validationAttribute. ErrorMessage = validationAttribute.
FormatErrorMessage(formattedPropertyName); } } This code runs at the same time as the code in the question (as part of the CreateMetadata method in the custom metadata provider). It works in all of the cases I've tested, but it's not really providing the metadata to the validation provider so much as formatting the error string using a Pascal cased version of the property name. This works with the way that most of the normal validation messages are setup.
The fact that it is explicitly setting the error message on the validation attributes doesn't seem correct. I don't known that this is would work as a global solution, however. This solution "works", but I hope that a better solution is available.
I still have the same reservations with this answer as I did when I originally added it. I haven't been able to find a better solution, however, so am marking it as the accepted answer unless/until a better solution is added. – ajalexander Aug 12 at 13:22.
I'm on my phone at the moment, so don't have the benefit of reflector or an IDE, however I don't think you can do this without changing the validators, because their behaviour is to use the format string of the error message, passing in the same display name that you have modified here. I could be wrong though (i do like your approach here). I have done what you've done, however, by writing custom editor templates, which also puts the control of the html in the hands of the web developer.
Using the metadata approach you can't give the asterisk, say, its own class for colouring purposes. Even better with using templates, if using razor, you can use a layout template so that all field types can use a standard label/input approach. Using Html.
LabelFor, followed by an optional block if the current model is required offers a lot of flexibility I think, and I would prefer that over the metadata solution since it also doesn't interfere with the validation messages. Like I say, on my initial doubt, though,I could be wrong :).
After spending some more time thinking about the problem, I managed to come up with something that seems to work. I don't really love the solution, however.
I'm on my phone at the moment, so don't have the benefit of reflector or an IDE, however I don't think you can do this without changing the validators, because their behaviour is to use the format string of the error message, passing in the same display name that you have modified here. I could be wrong though (i do like your approach here).
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.