加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – StringLengthAttribute和本地化文本

发布时间:2020-12-15 08:27:32 所属栏目:百科 来源:网络整理
导读:以下代码是从MSDN: http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.stringlengthattribute.aspx中获取的 [MetadataType(typeof(ProductMetadata))]public partial class Product{}public class ProductMetadata{ [Scaffol
以下代码是从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;

}

如何将本地化文本(例如:从资源文件中)应用于错误消息?

解决方法

使用 ValidationAttribute.ErrorMessageResourceType属性引用资源文件,使用 ValidationAttribute.ErrorMessageResourceName属性引用该资源文件中的字符串名称.例如:
[StringLength(4,ErrorMessageResourceType = typeof(YourResourceFileHere),ErrorMessageResourceName = "NameOfStringInResourceFile")]

如果您需要更多示例,还可以查看this blog post.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读