我想本地化/全局化我的登录页面上的字段。我正在使用ASP.NET MVC 3 Preview 1和剃须刀视图引擎。本地化ASP.NET MVC的AccountModel上的字段/属性
一些背景
首先,我已经把我的路由,并添加本地化属性的处理程序,这样我可以写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>
任何想法的例子吗?
我已经看到了这一点,但它不能帮助我很多,因为'DisplayAttribute'不MVC 3,正常工作 – 2010-08-18 18:42:08
没关系,一个资源文件的构建操作是错误的。谢谢。 – 2010-08-19 06:12:35