Apr 15, 2011 at 9:06 PM
Edited Apr 15, 2011 at 9:18 PM
I am trying to determine the best way of supporting Localization in Validator messages. It appears
MessageTemplateResourceName and MessageTemplateResourceType should do the trick for Message Templates. However, I don't seem to find a similar construct in case of the
Tag property of validator attribute decorators. If I embed a string in the Tag property of the attribute, in another culture, the final validation failure message will be a mix of two languages: English for the Tag part and another language
for the rest of the message.
Is there some way to declaratively or programmatically set the Tag property value from an external resource file?
A related question: is it possible to assign an overall MessageTemplate string at the method level if I am doing validation at the method argument level. So, for instance, lets say I have the following code:
public void DoSomething
I want to display a message like "DoSomething Failed" and pre-pend to whatever message the validators returned. So I want to always have the validators display a generic message like "'A' cannot be null'" but the method level message adds context to the
error message so user knows where exactly the validation failed. i.e. the final user message would be 'Do Something Failed: 'A' cannot be null"
Obviously, my preference is to be able to pull this method level message from a resx file so I can localize the code later to other cultures.