1

I know there's a DisplayName and Display for model properties like so :

public class MyModel
{
    [Display(Name = "Licence")]
    public string Licence { get; set; }
}

But is there a Display for the whole model ? May be something like this :

[Display(Name = "My beautiful model")]
public class MyModel
{
...

And if so, how to access it from HTML ?

Mehdiway
  • 10,337
  • 8
  • 36
  • 68

2 Answers2

6

You could add another property to your model called Title and then in the get set that like so

public string PageTitle
{
    get
    {
        return "Attribut de licence";
    }
}

This could work. This is quite crude, but I don't think you can add a display attribute to a model itself.

Canvas
  • 5,779
  • 9
  • 55
  • 98
1

Have you tried to override ToString method ?

public override string ToString()
{
    var sb = new StringBuilder();
    sb.Append(Name)
      .Append(" ")
      .Append(Surname);
    return sb.ToString();
}
WholeLifeLearner
  • 455
  • 4
  • 19