繁体   English   中英

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

[英]Localizing the fields / attributes on the AccountModel for ASP.NET MVC

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

一些背景

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

问题

在根的App_GlobalResources有一个名为Account.resx的文件我当然想象我应该可以从我的页面访问它。 在我的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可能包含的LogOn.cshtml

<div class="editor-label">
    @Html.LabelFor(m => m.UserName)
</div>

有任何想法吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM