gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 01:57:45 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com