title: Dataannotations localization
body: <p><strong>model</strong></p>
  
  <pre><code>[MetadataType(typeof(UserMetaData))]
  public class User
  {
      public int Id { get; set; }
      public string UserName { get; set; }
  }
  
  public class UserMetaData
  {
      public int Id { get; set; }
  
      [Required(ErrorMessageResourceType = typeof(Resources.ModelValidation), ErrorMessageResourceName = "UserNameRequired")]
      [LocalizedDisplayNameAttribute("UserName", NameResourceType = typeof(Resources.ModelValidation))]
      public string UserName { get; set; }
  }
  </code></pre>
  
  <p><strong>view</strong></p>
  
  <pre><code>@using (Html.BeginForm())
  {
      &lt;div&gt;
          @Html.LabelFor(x =&gt; x.UserName)
          @Html.TextBoxFor(x =&gt; x.UserName)
          @Html.ValidationMessageFor(x =&gt; x.UserName)
      &lt;/div&gt;
      &lt;div&gt;
          &lt;input type="submit" value="Gönder" /&gt;
      &lt;/div&gt;
  }
  </code></pre>
  
  <p><strong>LocalizedDisplayNameAttribute</strong></p>
  
  <pre><code>public class LocalizedDisplayNameAttribute : DisplayNameAttribute
  {
      private PropertyInfo _nameProperty;
      private Type _resourceType;
  
      public LocalizedDisplayNameAttribute(string displayNameKey)
          : base(displayNameKey)
      { }
  
      public Type NameResourceType
      {
          get { return _resourceType; }
          set
          {
              _resourceType = value;
              //initialize nameProperty when type property is provided by setter  
              _nameProperty = _resourceType.GetProperty(base.DisplayName, BindingFlags.Static | BindingFlags.Public);
          }
      }
      public override string DisplayName
      {
          get
          {              
              //check if nameProperty is null and return original display name value  
              if (_nameProperty == null) { return base.DisplayName; }
              return (string)_nameProperty.GetValue(_nameProperty.DeclaringType, null);
          }
      }
  }
  </code></pre>
  
  <p><strong>resource file</strong></p>
  
  <p><img src="https://i.stack.imgur.com/EIE5G.png" alt="enter image description here"></p>
  
  <p><strong>output</strong></p>
  
  <p><img src="https://i.stack.imgur.com/T5IiB.png" alt="enter image description here"></p>
  
  <p>RequiredAttribute localization works, but LocalizedDisplayNameAttribute does not work. I cant find any solution to fix this.</p>
  
  <p>Any suggestion, where is the missing?</p>