开发者

Can I set dynamic text to ErrorMessage in Required attribute?

开发者 https://www.devze.com 2023-02-28 09:58 出处:网络
is it possible to make Required error message attribute available in different languages according to a resource file or configuration开发者_如何学JAVA?

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

精彩评论

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