As we can use System.ComponentModel.DataAnnotations.DisplayAttribute
to set a label for a property, I want to use it for the class but it is not allowed on classes.
using System.ComponentModel.DataAnnotations;
[Display(Name = "A person")]
public class Person
{
[Display(Name = "A name")]
public string Name { get; set; }
}
Is anyone know a workaround for that ?
EDIT : I want to use it on a strongly typed view. When I create a new strongly typed view, the class name is hard coded in HTML, like that :
@model Models.Person
<fieldset>
<legend>Person</legend>
<div class="display-label">
@Html.LabelFor(model => model.Name)
</div>
</fieldset>
I want to do something similar to the Name
property.
For that we can use the Display attribute. DisplayAttribute or Display or DisplayName attribute: DisplayAttribute and Display is present in the System. ComponentModel. DataAnnotations namespace.
DisplayName. Gets the display name for a property, event, or public void method that takes no arguments stored in this attribute.
The DisplayName
attribute (from System.ComponentModel
) performs a similar function and can be applied to a class.
MSDN
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With