Model /// <summary>
/// 邮箱地址
/// </summary>
[Display(Name="邮箱地址")]
[Required(ErrorMessage="邮箱地址必须输入!")]
[DataType(DataType.EmailAddress)]
[RegularExpression(@"^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$", ErrorMessage = "邮箱格式不正确!")]
[Remote("IsExists","Account",ErrorMessage="该邮箱已被注册!")]
public string Email { get; set; }
View <div class="editor-label">
@Html.LabelFor(model => model.Email)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.Email)
@Html.ValidationMessageFor(model => model.Email)
</div>
我在程序第一次执行后,输入[email protected],焦点失去时,Model验证开始并执行[Remote]的IsExists。此时还一切正常。
但是当焦点再回到email中,我发现每按一个键都会触发一次验证。比如我最终想输入[email protected]。那么我将会触发三次,分别是[email protected]、[email protected]、[email protected]。有什么方法能让验证触发在焦点失去时呢?
/// 邮箱地址
/// </summary>
[Display(Name="邮箱地址")]
[Required(ErrorMessage="邮箱地址必须输入!")]
[DataType(DataType.EmailAddress)]
[RegularExpression(@"^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$", ErrorMessage = "邮箱格式不正确!")]
[Remote("IsExists","Account",ErrorMessage="该邮箱已被注册!")]
public string Email { get; set; }
View <div class="editor-label">
@Html.LabelFor(model => model.Email)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.Email)
@Html.ValidationMessageFor(model => model.Email)
</div>
我在程序第一次执行后,输入[email protected],焦点失去时,Model验证开始并执行[Remote]的IsExists。此时还一切正常。
但是当焦点再回到email中,我发现每按一个键都会触发一次验证。比如我最终想输入[email protected]。那么我将会触发三次,分别是[email protected]、[email protected]、[email protected]。有什么方法能让验证触发在焦点失去时呢?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货