StringLengthAttribute 和本地化文本
以下代码是从 MSDN 获取的: http:// msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.stringlengthattribute.aspx
[MetadataType(typeof(ProductMetadata))]
public partial class Product
{
}
public class ProductMetadata
{
[ScaffoldColumn(true)]
[StringLength(4, ErrorMessage = "The ThumbnailPhotoFileName value cannot exceed 4 characters. ")]
public object ThumbnailPhotoFileName;
}
如何将本地化文本(例如:来自资源文件)应用于错误消息?
The following code was grabbed from MSDN: http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.stringlengthattribute.aspx
[MetadataType(typeof(ProductMetadata))]
public partial class Product
{
}
public class ProductMetadata
{
[ScaffoldColumn(true)]
[StringLength(4, ErrorMessage = "The ThumbnailPhotoFileName value cannot exceed 4 characters. ")]
public object ThumbnailPhotoFileName;
}
How can I apply localize text (ex: from a Resource file) to the error message?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
ValidationAttribute.ErrorMessageResourceType
属性引用您的资源文件,以及ValidationAttribute.ErrorMessageResourceName
属性引用该资源文件中的字符串名称。例如:如果您需要更多例子。
Use the
ValidationAttribute.ErrorMessageResourceType
property to refer to your resource file, and theValidationAttribute.ErrorMessageResourceName
property to refer to the name of the string within that resource file. For example:You can also check out this blog post if you need more examples.