2

我正在研究在 MVC4 中创建编辑器模板的示例。

我在我的模型中添加了以下内容:

[Required]
[DataType(DataType.EmailAddress)]
[Display(Name = "Email"]
public string Email { get; set; }

将此添加到模型的视图中:

@Html.EditorFor(m => m.Email)

并使用以下行创建了一个名为 EmailAddress.cshtml 的 EditorTemplate:

 @Html.TextBox("", null, new {@class="text-box single-line", type="email", placeholder="Enter an email address"})

在将 Display 属性更改为以下内容之前,我无法在 Chrome 中显示占位符:

[Display(Name = "Email address")]

有人可以向我描述为什么在我更改它之前它不起作用吗?该属性与我调用 EditorFor 时生成的内容之间有什么关系,以及此更改如何导致占位符正确显示?

谢谢。

4

1 回答 1

1

在模型中,装饰者

 [Display(Name = "Some Name")]
 public string myproperty{get;set;}

用于在视图中显示标签,通过

@Html.Labelfor(m=>m.myproperty)

我相信它与占位符无关

于 2014-12-23T13:55:58.970 回答