views:

219

answers:

1

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.

+1  A: 

Everything is working as designed here.

You already know your answer. If you display a form for IRole you must also have the attributes on IRole.


In order to have the correct labels you'd have to implement your own TypeDescriptors or ModelMetadataProvider in order to "smush" together the metadata for an interface into any concrete classes that implement them.

This will become really complex real fast.

Why can't you just add the attribute to the IRole interface?

jfar