如何从ASP.Net Core(3.1)中的模型引用资源文件?

问题描述 投票:0回答:2

因此,我阅读了有关ASP.Net Core(3.1)中新的本地化系统的全部信息,并成功地使用了IStringLocalizer<MyController>IViewLocalizer<MyView>。我也可以对模型中的[DisplayName("Property description")使用本地化。

在我看来无法之下要做:在旧的.Net Framework中,我可以这样做:

 public class Month
{
    public int MonthNumber { get; set; }

    public string  Name
    {
        get
        {
            switch(MonthNumber)
            {
                case 1:
                    return Properties.Resources.Jan;
                case 2:
                    return Properties.Resources.Feb;
                default:
                    return "?";
            }
        }
    }

但是如何在ASP.Net Core 3.1中的模型中做到这一点?

asp.net-core model localization resource-files
2个回答
1
投票

您需要在课程上加入IStringLocalizer


0
投票

我这样解决了:

© www.soinside.com 2019 - 2024. All rights reserved.