我正在研究一个在 MVC4 中创建编辑器模板的示例。
我将以下内容添加到我的模型中:
[Required]
[DataType(DataType.EmailAddress)]
[Display(Name = "Email"]
public string Email { get; set; }
将此添加到模型的 View 中:
@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 时生成的内容之间的关系是什么?此更改如何导致占位符正确显示?
谢谢。
最佳答案
在模型中,装饰器
[Display(Name = "Some Name")]
public string myproperty{get;set;}
用于在 View 中显示标签,这些标签通过
访问@Html.Labelfor(m=>m.myproperty)
我相信它与占位符无关
关于c# - MVC的Display装饰器和使用EditorFor应用的View是什么关系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15969785/