[英]MVC on unobtrusive validation fire method
当非侵入式验证返回错误时,我正在尝试在MVC视图上运行方法。 我当前的脚本根本不会触发。 我试图仅在返回错误时运行某种方法。
我试过$("#submitButton").click
和类似方法,但无济于事。
无论如何,仅从内联脚本执行此操作? 验证是否有任何触发器?
<fieldset class="step">
<legend>
Contact:
</legend>
<p>Let us know how we can contact you with your quote, or anything else we may need from you coming up to your ski trip. </p>
<div style=" float: left;">
<table>
<tr style="height: 50px; padding: 5px;">
<td style="width: 187px;">
Full Name*
</td>
<td>
@Html.DropDownListFor(x => x.Title, Model.Titles, "...........", new { style = "width:70px; padding: 5px;" })
@Html.TextBoxFor(x => x.FirstName, new { style = "width:115px; padding: 5px;" })
@Html.TextBoxFor(x => x.LastName, new { style = "width:115px; padding: 5px;" })
</td>
</tr>
<tr style="height: 50px; padding: 5px;">
<td style="width: 187px;">
City*
</td>
<td>
@Html.TextBoxFor(x => x.City, new { style = "width:320px; padding: 5px;" })
</td>
</tr>
<tr style="height: 50px; padding: 5px;">
<td style="width: 187px;">
Postcode*
</td>
<td>
@Html.TextBoxFor(x => x.Postcode, new { style = "width:320px; padding: 5px;" })
</td>
</tr>
<tr style="height: 50px; padding: 5px;">
<td style="width: 187px;">
Email*
</td>
<td>
@Html.TextBoxFor(x => x.Email, new { style = "width:320px; padding: 5px;" })
</td>
</tr>
<tr style="height: 50px; padding: 5px;">
<td style="width: 187px;">
Telephone*
</td>
<td>
@Html.TextBoxFor(x => x.Telephone, new { style = "width:320px; padding: 5px;" })
</td>
</tr>
<tr style="height: 50px; padding: 5px;">
<td style="width: 187px;">
Preferred Time of Contact
</td>
<td>
@Html.TextBoxFor(x => x.PreferredTime, new { style = "width:200px; padding: 5px;" })
</td>
</tr>
</table>
</div>
<input id="submitButton" type="image" alt="Submit" src="/images/global/submit_button.gif" />
</fieldset>
编辑:只是尝试绑定到invalid-form.validate方法,它没有用:
$(function () {
$("form").bind("invalid-form.validate", function () {
alert('invalid!');
});
});
var controls = $("#divid").find('.class');
$.each(controls, function (index, item) {
$("#form1").validate().element($(this));
if ($(this).valid) {
//skip it maybe
} else {
//do something, even an ajax call if need be
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.