ASP.net MVC验证挂钩 [英] ASP.net MVC Validation Hook

本文介绍了ASP.net MVC验证挂钩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASP.net以下几种观点MVC 3:

I have the following view in 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>
}

我使用与jQuery和流利的验证框架不显眼的JavaScript。

I am using unobtrusive javascript with jQuery and the Fluent Validation framework.

当我点击保存按钮,验证失败,有没有一些事件中,我可以挂接到调用一些自定义的javascript?

When I click the Save button and validation fails, is there some event I can hook into to call some custom javascript?

function validationFailed() {
    // do something here only if validation failed
}

怎么会扎入验证,这样,当它失败(且仅当它失败)我可以打电话给我的validationFailed()函数。

How would I tie into the validation so that when it failed (and only if it failed) I could call my validationFailed() function.

推荐答案

您可以使用 invalidHandler ,我相信这是在jQuery验证。

You can use the invalidHandler, I believe that is in jquery validation.

invalidHandler回调结果
  当一个无效的提交表单自定义code回调。叫
  一个事件对象作为第一个参数,并验证为
  第二。

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.

这篇关于ASP.net MVC验证挂钩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆