开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜