我有以下ViewModel:
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>
当您只填写FirstName时,会收到一条错误消息,指出LastName丢失,这很好。但是当您填写LastName时,错误消息仍然存在(当您移动到其他输入字段时)。
请参阅此屏幕截图:
我正在使用: