C# MVC 2-标签的数据注释?

C# MVC 2-标签的数据注释?,c#,model-view-controller,model,C#,Model View Controller,Model,是否有注释来设置属性的标签名称 例: 谢谢 然后在视图中,它会显示名称“你的手机” 如果您指的是要在页面上显示的标签的实际内容,则为“是”。是的 [Display (Name= "Your Display content")] 使用[DisplayName(“您的手机”)]而不是[LabelName(“您的手机”)]根据我看到的答案,虽然这是一篇旧文章,但下面是独家新闻: (我正在使用MVC5) DisplayName–定义我们希望在表单字段和验证消息上使用的文本 但是我想说的是,要坚持使用更

是否有注释来设置属性的标签名称

例:

谢谢

然后在视图中,它会显示名称“你的手机”


如果您指的是要在页面上显示的标签的实际内容,则为“是”。是的

[Display (Name= "Your Display content")]

使用
[DisplayName(“您的手机”)]
而不是
[LabelName(“您的手机”)]

根据我看到的答案,虽然这是一篇旧文章,但下面是独家新闻: (我正在使用MVC5)

DisplayName–定义我们希望在表单字段和验证消息上使用的文本

但是我想说的是,要坚持使用更好、更灵活的-->显示(Name=

您可以使用这两种方法中的任何一种

[Display(Name = "Add Comments")]
正在使用此命名空间的:

using System.ComponentModel.DataAnnotations;
using System.ComponentModel;

[DisplayName("Add Comments")]
正在使用此命名空间的:

using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
对于我(MVC 5),只有
[Display(Name=“somethine nice”)]
可以如下所示工作。而且
[DisplayName
不编译。我认为Intellisense将引导大多数读者朝着正确的方向前进,但仍然认为接受的答案应该更改为下面的答案。因此,我的-1:)。