我在ASP.net MVC 3中有以下视图:
@model Models.CreateProjectviewmodel <script type="text/javascript" src="@Url.Content("~/Scripts/jquery.validate.min.js")"></script> <script type="text/javascript" src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")"></script> @using( Html.BeginForm() ) { @Html.TextBoxFor(m => m.ProjectName) @Html.ValidationMessageFor(m => m.ProjectName) <p> <input type="submit" value="Save" /> </p> }
我正在使用不引人注目的JavaScript与jQuery和流畅的验证框架。@H_502_5@
当我点击保存按钮和验证失败,是否有一些事件我可以挂钩来调用一些自定义javascript?@H_502_5@
function validationFailed() { // do something here only if validation Failed }
我如何绑定到验证,以便当它失败(并且只有失败),我可以调用我的validationFailed()函数。@H_502_5@
解决方法
可以使用
invalidHandler
,我相信是在jquery验证。
invalidHandler Callback Callback for custom code when an invalid form is submitted. Called with a event object as the first argument,and the validator as the second.@H_502_5@