ASP.NET MVC DisplayAttribute and interfaces
        Posted  
        
            by msi
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by msi
        
        
        
        Published on 2010-04-16T12:18:46Z
        Indexed on 
            2010/04/16
            12:23 UTC
        
        
        Read the original article
        Hit count: 631
        
asp.net-mvc
|dataannotations
I have some interface and classes
public inteface IRole
{
  int Id { get; }
  string Name { get; set; }
}
public class Role : IRole
{
  public int Id { get; }
  [Display("Role Name")]
  public string Name { get; set; }
}
public class Member 
{
  [Display("Login")]
  public string Login { get; set; }
  [Display("Password")]
  public string Password { get; set; }
  public IRole Role { get; set; }
}
on View I try to use, View is strongly type of Member
on this line displays correct message from DisplayAttribute
<%= Html.LabelFor(m => m.Login) %>
on this line it does not display correct label from DisplayAttribute
<%= Html.LabelFor(m => m.Role.Name) %>
How can I fix this to have correct labels in such architecture?
Thanks
P.S. I know about adding DisplayAttribute to the interface field and all will work, but maybe there are different solution.
© Stack Overflow or respective owner