c# - MVC的Display装饰器和使用EditorFor应用的View是什么关系?

标签 c# html asp.net-mvc-4

我正在研究一个在 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/

相关文章:

html - 当页面大小发生变化时,在固定导航栏的中心对齐图像时出现问题

c# - ASP.NET MVC 路由将用户从局部 View 返回到原点

asp.net-mvc-4 - 具有多个尖括号问题的 MVC 4 Razor 模型

c# - Razor 引擎的任何好的替代品

c# - 命名空间中不存在名称

php - 内联 PHP/HTML 三元 If

c# - 如何访问不在Resources文件夹根目录下的资源文件? (共享点 2010)

javascript - 我在 javascript 中执行 setTimeout 加载符号?

c# - 在 Angular 6 中传递带有空字符串的整数值时不调用 API Get 方法

C# 等效于 C sscanf