MVC 5 中 @Html.EditorFor(model => model.Name) 中的占位符
Placeholder in @Html.EditorFor(model => model.Name) in MVC 5
我在 Controller 中使用了 [prompt("name")]
并且
@Html.EditorFor(model => model.Email,
new {placeholder=ViewData.ModelMetadata.Watermark})`
可见,但没有显示
我还使用了 Html5 Placeholders with .NET MVC 3 Razor EditorFor extension? 的帮助
但什么也没发生
我需要 @EditorFor 的占位符而不是文本框
感谢任何帮助
EditorFor 不接受 HtmlAttribut 参数,您必须使用 TextBoxFor 代替它;)
试试这个:
@Html.TextBoxFor(model => model.Email, new {placeholder=ViewData.ModelMetadata.Watermark})`
只用 TextBoxFor 为我工作。
@Html.TextBoxFor(model => model.emailContact, new {@placeholder = "Your Placeholder Text" }
您可以使用以下语法将 HTML 属性写入 Html.EditorFor
。确保在 class 和占位符之前使用 @,以便渲染器知道这是 HTML 标记。
@Html.EditorFor(model => model.Email, new {
htmlAttributes = new {
@class = "form-control",
@placeholder = "Email Address"
}
})
我在 Controller 中使用了 [prompt("name")]
并且
@Html.EditorFor(model => model.Email,
new {placeholder=ViewData.ModelMetadata.Watermark})`
可见,但没有显示 我还使用了 Html5 Placeholders with .NET MVC 3 Razor EditorFor extension? 的帮助 但什么也没发生 我需要 @EditorFor 的占位符而不是文本框 感谢任何帮助
EditorFor 不接受 HtmlAttribut 参数,您必须使用 TextBoxFor 代替它;) 试试这个:
@Html.TextBoxFor(model => model.Email, new {placeholder=ViewData.ModelMetadata.Watermark})`
只用 TextBoxFor 为我工作。
@Html.TextBoxFor(model => model.emailContact, new {@placeholder = "Your Placeholder Text" }
您可以使用以下语法将 HTML 属性写入 Html.EditorFor
。确保在 class 和占位符之前使用 @,以便渲染器知道这是 HTML 标记。
@Html.EditorFor(model => model.Email, new {
htmlAttributes = new {
@class = "form-control",
@placeholder = "Email Address"
}
})