问题
So I need to localize this
[Range(1, 150, ErrorMessage = "")]
I tried to use
[Range(1, 150, ErrorMessage = MyApp.Properties.Resource.ErrorMessageMustBeBetween)]
where MyApp.Properties.Resource.ErrorMessageMustBeBetween
is
"{0} must be between {1} and {2}."
and it says
An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type
How it could be done then? Thank you!
回答1:
You need to use ErrorMessageResourceType
and ErrorMessageResourceName
to use a resource for a Data Annotation.
Try:
[Range(1, 150, ErrorMessageResourceType = typeof(MyApp.Properties.Resource), ErrorMessageResourceName = "ErrorMessageMustBeBetween")]
来源:https://stackoverflow.com/questions/25160778/how-to-localize-range-attribute