现在有一个页面,如果我把一个必需的字段留空,我会得到这些验证弹出窗口:
这是上面图像的代码:
<p class=“control label col-md-5”><i class=“fa fa感叹三角形”aria hidden=“true”></i><b>voorletter(s)</b></p>
@html.validationmessagefor(model=>model.voorletters,“”,new@class=“text danger”)
</DIV>
<p class=“control label col-md-5”><i class=“fa fa感叹三角形”aria hidden=“true”></i><b>功能</b></p>
@html.editorfor(model=>model.functie1,new htmlattributes=new@class=“form control”,required=“required”)
</DIV>
编辑:
[metadatatype(typeof(medewerkermetadata))]
{
公共字符串voorletters_get;set;
}
<div class="form-group">
<p class="control-label col-md-5"><i class="fa fa-exclamation-triangle triangle" aria-hidden="true"></i> <b>Voorletter(s)</b></p>
<div class="col-md-4">
@Html.EditorFor(model => model.Voorletters, new { htmlAttributes = new { @class = "form-control", required = "required", placeholder="K" } })
@Html.ValidationMessageFor(model => model.Voorletters, "", new { @class = "text-danger" })
</div>
</div>
![enter image description here](https://i.stack.imgur.com/2K5XC.png)
<div class="form-group">
<p class="control-label col-md-5"><i class="fa fa-exclamation-triangle triangle" aria-hidden="true"></i> <b>Functie</b></p>
<div class="col-md-4">
@Html.EditorFor(model => model.Functie1, new { htmlAttributes = new { @class = "form-control", required = "required" } })
@Html.ValidationMessageFor(model => model.Functie1, "", new { @class = "text-danger" })
</div>
</div>
但是我更喜欢后一种选择,我怎么总是得到它呢?
编辑:
[MetadataType(typeof(medewerkerMetaData))]
public partial class medewerker
{
public partial class medewerkerMetaData
{
//[Required(ErrorMessage = "Verplicht invullen!")]
public string Voorletters { get; set; }
// more code
}
}