当不显眼的验证返回错误时,我正在尝试在我的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!');
});
});
答案 0 :(得分:1)
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
}