Asp.net核心ViewModel DataAnnotations本地化

时间:2016-09-18 11:04:29

标签: mvvm localization asp.net-core asp.net-core-mvc globalization

我最近在Asp.Net Core MVC上练习。在使用下面的类和覆盖之前,我们能够本地化和全球化ViewModel属性。我一直在寻找这个解决方案一周。

public class LocalizedDisplayNameAttribute : DisplayNameAttribute
{
    public LocalizedDisplayNameAttribute(string resourceId)
        : base(GetMessageFromResource(resourceId))
    {
    }

    private static string GetMessageFromResource(string resourceId)
    {
        //return value from whatever the source is.
    }
}

我的视图模型看起来像

public class LoginViewModel
{
    [CustomRequiredAttribute("Email")]
    [LocalizedDisplayName("Email")]
    [EmailAddress]
    public string Email { get; set; }

    [LocalizedDisplayName("Password")]
    [CustomRequiredAttribute("Password")]
    [DataType(DataType.Password)]
    public string Password { get; set; }

    [Display(Name = "Remember me?")]
    public bool RememberMe { get; set; }
}

我复制了相同的LocalizedDisplay类并在Asp.Net核心上尝试过但没有用。

问题在于视图,应用程序打印字段名称而不是属性值。

1 个答案:

答案 0 :(得分:1)

问题解决了:这个问题出现在githubb https://github.com/dotnet/corefx/issues/11846#issuecomment-248148026

相关问题