gpt4 book ai didi

asp.net-core - ASP.NET Core DisplayAttribute 本地化

转载 作者:行者123 更新时间:2023-12-02 01:15:31 27 4
gpt4 key购买 nike

根据documentation :

The runtime doesn’t look up localized strings for non-validation attributes. In the code above, “Email” (from [Display(Name = "Email")]) will not be localized.

我正在寻找一种在 DisplayAttribute 中本地化文本的方法。有什么建议以正确的方式做到这一点吗?

最佳答案

您可以在 DisplayAttribute 上设置可用于本地化文本的 ResourceType

将资源 .resx 文件添加到您的项目中,例如MyResources.resx,并为您的字段添加资源:

enter image description here

然后在 DisplayAttribute 中引用字段名称和 MyResources 类型

[Display(Name = "RememberMe", ResourceType  = typeof(MyResources))]
public bool RememberMe { get; set; }

本地化资源将自动拉取(参见文本框)

enter image description here

关于asp.net-core - ASP.NET Core DisplayAttribute 本地化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37833661/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com