ITPub博客

首页 > 应用开发 > > ASP.NET Core 的模型验证,如何快速的实现多语言错误信息

ASP.NET Core 的模型验证,如何快速的实现多语言错误信息

作者:daqianmen 时间:2019-09-02 10:48:17 0 删除 编辑

Model:

public class PmTbl

{

[MaxLength(10), Required, Key]

public string Pm { get; set; }

[MaxLength(50), Required]publicstringDescr {get;set; };

}

Action:

可以在 Model 里的添加特性的方式实现多语言错误信息,但这样太麻烦,每个字段都要写:

MaxLength(50, ErrorMessageResourceName ="xxx",ErrorMessageResourceType =typeof(T))

有没有地方可以直接翻译“The field Descr must be a string or array type with a maximum length of '50'.” 来实现多语言的?

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1727/viewspace-3120486/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-07-31

  • 博文量
    108
  • 访问量
    34266