我有一个简单的模型,其属性如下所示。
[Required(ErrorMessage = "User name is Required")]
[Display(Name = "User name")]
public virtual string Inserted_By
{
get;
set;
}
public virtual int FK_ClientID
{
get;
set;
}
我的观点是这样的。
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Booking</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Inserted_By)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Inserted_By)
@Html.ValidationMessageFor(model => model.Inserted_By)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.FK_ClientID)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.FK_ClientID)
@Html.ValidationMessageFor(model => model.FK_ClientID)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
如果我尝试在FK_ClientID字段中输入文本,我会得到“字段FK_ClientID必须是数字”,这是正确的。但是,如果我在Inserted_By文本框中没有输入任何内容,则它不会验证??