我想为字符串创建模板,其中包括标签、带水印的文本框和注册表单的验证消息。另外,我想补充一点通知(例如星号),该字段是从模型中获取的必需字段。
到目前为止,我已经在 ~/Views/Account/EditorTemplates 中创建了包含以下内容的文件 string.cshtml:
<span class="editor-label>@Html.Label(ViewData.ModelMetadata.Watermark)</span>
<span class="editor-field">@Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, new { placeholder = ViewData.ModelMetadata.Watermark })</span>
<span class="error_message">@Html.ValidationMessage(ViewData.ModelMetadata.PropertyName)</span>
模型如下所示:
[Required]
[DataType(DataType.Text)]
[Display(Prompt = "First name")]
public string FirstName { get; set; }
鉴于我称之为如下:
@Html.EditorFor(m => m.FirstName)
有谁知道,我哪里出错了?