MVC DataAnnotation DisplayName not working for virtual item

I have an Entity class that includes a virtual list that is a reference to another class:

        public virtual Employee Employee1 { get; set; }

So, on the edit page, I have my element labeled Employee1 when I need "My Employee", so in my DataAnnotation class I add

[DisplayName("My Employee")]
public virtual Employee Employee1 { get; set; }

But it does not work yet. Other elements of the DataAnnotation class work well.

+4
source share
2 answers

It did not work, because the visual studio, when automatically creating a view for foreign keys, uses Labelfor instead of DisplaynameFor, as shown below:

            @Html.LabelFor(model => model.Employee1.LastName, "Employee1")

, DataAnnotation, :

           @Html.LabelFor(model => model.Employee1.LastName, "My Employee")
+4

DataAnnotation . DataAnnotation , . . DataAnnotation . .

:

public partial class Languages
{
   DataAnnotation  here
    public string Code { get; set; }
    public string Name { get; set; }
}



public partial class Categories
{

    public string Code { get; set; }
    public string FKLanguageCode { get; set; }
    public string Name { get; set; }
    public Nullable<int> Order { get; set; }

     DataAnnotation Not Here
    public virtual Languages Languages { get; set; }
 }
0

All Articles