Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC 2 - Data Annotation for Label?

Is there an annotation to set the Label-name of the property?

Ex:

public class MyModel
{

[LabelName("Your Phone")]
public string Phone{get;set;}
}

Thanks

And then in the view, it would show the name "Your Phone"

<%=Html.LabelFor(Model.Phone)%>
like image 746
WoF_Angel Avatar asked Nov 07 '11 12:11

WoF_Angel


People also ask

What is the data annotation in MVC?

In ASP.NET MVC, Data Annotation is used for data validation for developing web-based applications. We can quickly apply validation with the help of data annotation attribute classes over model classes.

What is System ComponentModel DataAnnotations?

Data annotations (available as part of the System. ComponentModel. DataAnnotations namespace) are attributes that can be applied to classes or class members to specify the relationship between classes, describe how the data is to be displayed in the UI, and specify validation rules.

What is DataAnnotations?

Data annotation is the categorization and labeling of data for AI applications. Training data must be properly categorized and annotated for a specific use case. With high-quality, human-powered data annotation, companies can build and improve AI implementations.


2 Answers

Use [DisplayName("Your Phone")] instead of [LabelName("Your Phone")]

like image 64
Pankaj Upadhyay Avatar answered Sep 22 '22 05:09

Pankaj Upadhyay


If you mean the actual content of the label to be displayed on the page, yes. It is

[Display (Name= "Your Display content")]
like image 31
Muthu Avatar answered Sep 24 '22 05:09

Muthu