太多人告诉我申请该required
课程以使该领域成为必填项。我不想要好的 ol'required
属性;我想要新的属性集进行验证。这是我尝试过但没有成功的方法:
这是我的编辑器模板:
@using Comair.RI.UI.Core
@{
var list = this.GetModelSelectList();
var listWithSelected = new SelectList(list.Items, list.DataValueField, list.DataTextField, Model);
}
@if (ViewData.ModelMetadata.IsRequired)
{
//var att = "data-val-required=\"string.Format("The {0} field is required", ViewData.ModelMetadata.DisplayName)
var att = string.Format("The {0} field is required.", ViewData.ModelMetadata.DisplayName);
@Html.DropDownListFor(m => Model, listWithSelected, " - select - ",
new Dictionary<string, object> {{"data-val-number=", "The field " + ViewData.ModelMetadata.DisplayName + " must be a number."}, {"data-val", true}, {"data-val-required", att}})
}