locked
LocalizedDisplayName fails once RRS feed

  • Question

  • User335759986 posted

    Hi,

    I am using MVC 2 Model Validation together with Localization. For some strange reason, everything works fine except for one translation, namely the word "Password". It should change into "Wachtwoord", the Dutch term, but it doesn't. I checked everything and I can't find what's wrong.


    So, there's the AccountModels.cs file, containing the class RegisterModel (which is the basis for the view file and validation). It looks like this:

    [PropertiesMustMatch("Password", "ConfirmPassword", ErrorMessageResourceName = "PasswordsMustMatch", ErrorMessageResourceType = typeof(ValidationStrings))]
        public class RegisterModel
        {
            [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ValidationStrings))]
            [LocalizedDisplayName("RegUsername", NameResourceType = typeof(Names))]
            public string Username { get; set; }
    
            [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ValidationStrings))]
            [DataType(DataType.EmailAddress)]
            [LocalizedDisplayName("RegEmailAdress", NameResourceType = typeof(Names))]
            public string Email { get; set; }
    
            [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ValidationStrings))]
            [ValidatePasswordLength(ErrorMessageResourceName = "PasswordMinLenght", ErrorMessageResourceType = typeof(ValidationStrings))]
            [DataType(DataType.Password)]
            [LocalizedDisplayName("RegPassword", NameResourceType = typeof(Names))]
            public string Password { get; set; }
    
            [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ValidationStrings))]
            [DataType(DataType.Password)]
            [LocalizedDisplayName("RegConfirmPassword", NameResourceType = typeof(Names))]
            public string ConfirmPassword { get; set; }
    
            [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ValidationStrings))]
            [LocalizedDisplayName("RegActivationCode", NameResourceType = typeof(Names))]
            public string ActivationCode { get; set; }
        }


    Obviously, there is also a Names.resx file which contains all the aforementioned "LocalizedDisplayName" elements:

     

    The Register.aspx file reads from this model:

    <div class="editor-label">
                        <%: Html.LabelFor(m => m.Username) %>
                    </div>
                    <div class="editor-field">
                        <%: Html.TextBoxFor(m => m.Username) %>
                        <%: Html.ValidationMessageFor(m => m.Username) %>
                    </div>
                    
                    <div class="editor-label">
                        <%: Html.LabelFor(m => m.Email) %>
                    </div>
                    <div class="editor-field">
                        <%: Html.TextBoxFor(m => m.Email) %>
                        <%: Html.ValidationMessageFor(m => m.Email) %>
                    </div>
                    
                    <div class="editor-label">
                        <%: Html.LabelFor(m => m.Password) %>
                    </div>
                    <div class="editor-field">
                        <%: Html.PasswordFor(m => m.Password)%>
                        <%: Html.ValidationMessageFor(m => m.Password)%>
                    </div>
                    
                    <div class="editor-label">
                        <%: Html.LabelFor(m => m.ConfirmPassword) %>
                    </div>
                    <div class="editor-field">
                        <%: Html.PasswordFor(m => m.ConfirmPassword) %>
                        <%: Html.ValidationMessageFor(m => m.ConfirmPassword) %>
                    </div>
                          
                    <div class="editor-label">
                        <%: Html.LabelFor(m => m.ActivationCode) %>
                    </div>
                    <div class="editor-field">
                        <%: Html.PasswordFor(m => m.ActivationCode)%>
                        <%: Html.ValidationMessageFor(m => m.ActivationCode)%>
                    </div>


    The HTML output is like:

     

    As you can see, everything gets translated correctly, except for "Password". Why would that be? Help?



    Wednesday, August 11, 2010 8:12 PM

All replies

  • User-1802908944 posted

    check your both line


     <div class="editor-label">  
                        <%: Html.LabelFor(m => m.Password) %>  
                    </div>  
                    <div class="editor-field">  
                        <%: Html.PasswordFor(m => m.Password)%>  
                  
          <%: Html.ValidationMessageFor(m => m.Password)%>  
                    </div>  
                      
                    <div class="editor-label">  
                        <%: Html.LabelFor(m => m.ConfirmPassword) %>  
                    </div>  
                    <div class="editor-field">  
                        <%: Html.PasswordFor(m => m.ConfirmPassword) %>  
                     
       <%: Html.ValidationMessageFor(m => m.ConfirmPassword) %>  
                    </div> 


    here you are using  <%: Html.PasswordFor( both password and confirm password


    please check




    Wednesday, August 11, 2010 11:50 PM
  • User335759986 posted

    The PasswordFor HTML helper generates a password box. I used it twice because it should be used twice. One time for the password, and one time for the confirm password. They are working just fine.

    The problem is the LabelFor HTML helper strangely enough does not receive/pull the translated value, but the original value. It outputs "Password" but should output "Wachtwoord".

     <%: Html.LabelFor(m => m.Password) %>  


    Thursday, August 12, 2010 12:41 PM