ASP.NET Core DisplayAttribute Localization

前端 未结 5 1012
挽巷
挽巷 2020-12-20 14:08

According to the documentation:

The runtime doesn’t look up localized strings for non-validation attributes. In the code above, “Email” (from [Display

5条回答
  •  遥遥无期
    2020-12-20 14:57

    You can set the ResourceType on the DisplayAttribute which can be used to localize your text.

    Add a resource .resx file to your project e.g. MyResources.resx, and add a resource for your field:

    Then reference the name of the field and the MyResources type in your DisplayAttribute

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

    The localized resource will be pulled through automatically (see the text box)

提交回复
热议问题