Dataannotations localization

淺唱寂寞╮ 提交于 2019-12-05 07:56:23
Darin Dimitrov

You seem to be reinventing the wheels with this LocalizedDisplayNameAttribute attribute. This functionality is already built into the framework, right into the [Display] attribute that you could use directly:

public class UserMetaData
{
    public int Id { get; set; }

    [Required(ErrorMessageResourceType = typeof(Resources.ModelValidation), ErrorMessageResourceName = nameof(Resources.ModelValidation.UserNameRequired)]
    [Display(ResourceType = typeof(Resources.ModelValidation), Name = nameof(Resources.ModelValidation.UserName))]
    public string UserName { get; set; }
}

As far as why your wheel reinvention doesn't work, well, can't say for sure. Why care when you could get rid of it anyways.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!