Can I set dynamic text to ErrorMessage in Required attribute?
is it possible to make Required error message attribute available in different languages according to a resource file or configuration开发者_如何学JAVA?
[Required(ErrorMessage = "Please enter your name")]
public string SenderName { get; set; }
We would like to make "Please enter your name"
a dynamic text, read from resources of config file.
Is it possible?
Attribute parameters need to be resolved in compile time, so this is not possible.
From MSDN:
Values passed to attributes must be known to the compiler at compile time.
You best option is to use satellite assemblies in the normal .NET internationalization scheme.
精彩评论