我有以下视图模型:
public class EmployeeVM : IEntity
{
[Remote("ValidateUniqueFullName", "Employee", AdditionalFields = "LastName,Id")]
public string First { get; set; }
[Remote("ValidateUniqueFullName", "Employee", AdditionalFields = "First,Id")]
public string LastName { get; set; }
}
视图是这样的:
<tr>
<td>
@Html.LabelFor(model => model.First)
</td>
<td>
@Html.TextBoxFor(model => model.First)
</td>
<td>
@Html.ValidationMessageFor(model => model.First)
</td>
</tr>
<tr>
<td>
@Html.LabelFor(model => model.LastName)
</td>
<td>
@Html.TextBoxFor(model => model.LastName)
</td>
<td>
@Html.ValidationMessageFor(model => model.LastName)
</td>
</tr>
当您只填写名字时,您会收到一条缺少姓氏的错误消息,这很好。但是当您填写姓氏时,错误消息仍然存在(当您移动到不同的输入字段时也是如此)。看这个截图:
我在用着:
- jQuery JavaScript 库 v2.0.3 (jquery-2.0.3.js)
- jQuery 验证插件 1.11.1 (jquery.validate.js)
- 用于 jQuery 和 jQuery Validate 的非侵入式验证支持库 (jquery.validate.unobtrusive.js)