Localizing Fields / Attributes in AccountModel for ASP.NET MVC

I want to localize / globalize the fields on my login page. I am using ASP.NET MVC 3 Preview 1 with a razor view engine.

Some background

First of all, I set my routing and added a localization attribute handler to write http://mysite.com/{lang}/{controller}/{action}/{id}. Now everything is working well. In my folder, ViewsI added a Home folder with the corresponding App_LocalResourcesso good. I can even add language files for different languages, such as Index.resxIndex.sv.resx`.

Problem

Having a file with a name Account.resxin the root directory App_GlobalResources, of course, I imagine that I should have access to this from my pages. In mine AccountModel.cs(which came with the setup / template project) I added the following to 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

english/default. /sv/ URL- , , , `` Account.sv.resx`.

, LogOn.cshtml

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

?

+5

All Articles