我希望使用资源以不同的语言显示名称。在下面的代码中有错误:
public class ChangePassword
{
[Display(Name = "CurrentPassword", ResourceType = typeof(SheardLocalization))]
public string CurrentPassword { get; set; }
[Display(Name = "NewPassword", ResourceType = typeof(SheardLocalization))]
public string NewPassword { get; set; }
}InvalidOperationException:无法检索属性“名称”,因为本地化失败。键入“CyengTeam.App.Models.SheardLocalization”不是公共的,或者不包含名称为“CurrentPassword”的公共静态字符串属性。
在视图(.cshtml)中,我可以使用@inject IHtmlLocalizer<SheardLocalization> localization;来处理资源,并且没有任何问题。但在课堂上有错误。
发布于 2021-05-03 05:14:05
您可以使用
[Required (ErrorMessageResourceName="SomeText", ErrorMessageResourceType=typeof(Resources.Resource))]这个问题发生在System.ComponentModel.DataAnnotations属性中。DisplayAttribute检查Type.IsVisible属性,而ValidationAttribute(RequiredAttribute从它们继承)不会。因此,您需要将资源类和属性更改为公共类以使其正常工作。您可以阅读更多的这里
https://stackoverflow.com/questions/67361385
复制相似问题