在Microsoft MVM的AccountModel上本地化字段/属性

时间:2010-08-18 11:51:59

标签: c# asp.net-mvc globalization

我想本地化/全球化我的登录页面上的字段。我正在使用带有剃刀视图引擎的ASP.NET MVC 3 Preview 1。

一些背景

首先,我设置了路由并添加了本地化属性处理程序,以便我可以编写http://mysite.com/{lang}/{controller}/{action}/{id}。现在这一切都很好。在我的Views文件夹中,我添加了一个主页文件夹,其中包含相应的App_LocalResources。我甚至可以为不同语言添加语言文件,例如Index.resx和Index.sv.resx`。

问题

在根Account.resx中有一个名为App_GlobalResources的文件我当然想象我应该可以从我的网页访问它。在我的AccountModel.cs(随安装/模板项目提供)中,我已将以下内容添加到LogOnModel

public class LogOnModel
{
    [Required]
    [Display(Name = "UserName", ResourceType = typeof(Account))]
    public string UserName { get; set; }

    [Required]
    [DataType(DataType.Password)]
    [Display(Name = "Password", ResourceType = typeof(Account))]
    public string Password { get; set; }

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

我的App_GlobalResource

中有两个文件
  • Account.resx
  • Account.sv.resx

实际上它确实采用了英文/默认文件中的文本。但是当我将/ sv /附加到我的URL或甚至确保文化是瑞典文时,它并没有将语言改为我的``Account.sv.resx`中的语言。

LogOn.cshtml

中的内容示例
<div class="editor-label">
    @Html.LabelFor(m => m.UserName)
</div>

有什么想法吗?

1 个答案:

答案 0 :(得分:0)