我在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和流畅的验证框架。
当我点击保存按钮和验证失败,是否有一些事件我可以挂钩来调用一些自定义javascript?
function validationFailed() { // do something here only if validation Failed }
解决方法
可以使用
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.