ASP.NET MVC2 - 勾成客户端验证 [英] ASP.NET MVC2 - hook into client side validation

查看:132
本文介绍了ASP.NET MVC2 - 勾成客户端验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想引发一些自定义的code在使用ASP.NET MVC2客户端验证更新客户端的错误。我已经找到了这个功能,我想钩到:

I want to trigger some custom code when the client side errors are updated using ASP.NET MVC2 client side validation. I've tracked down this function which I want to hook into:

Sys.Mvc.FormContext.prototype = {

    // ...

    _displayError: function Sys_Mvc_FormContext$_displayError() {
        if (this._validationSummaryElement) {
            if (this._validationSummaryULElement) {
                Sys.Mvc._validationUtil.removeAllChildren(this._validationSummaryULElement);
                for (var i = 0; i < this._errors.length; i++) {
                    var liElement = document.createElement('li');
                    Sys.Mvc._validationUtil.setInnerText(liElement, this._errors[i]);
                    this._validationSummaryULElement.appendChild(liElement);
                }
            }
            Sys.UI.DomElement.removeCssClass(this._validationSummaryElement, Sys.Mvc.FormContext._validationSummaryValidCss);
            Sys.UI.DomElement.addCssClass(this._validationSummaryElement, Sys.Mvc.FormContext._validationSummaryErrorCss);
        }
    },

    // ...

}    

我如何可以覆盖此功能,这样我的code能

How can I override this function such that my code can


  • 调用原函数

  • 然后做一些其他的工作

推荐答案

找到了。

<script type="text/javascript">
    $(function () {
        var old_displayError = Sys.Mvc.FormContext.prototype._displayError;
        Sys.Mvc.FormContext.prototype._displayError = function () {
            old_displayError.apply(this);
            // do other stuff here
        }
    });
</script>

我不习惯覆盖原型的功能,所以我难倒了一下。

I'm not used to overriding prototype functions, so I was stumped for a bit.

这篇关于ASP.NET MVC2 - 勾成客户端验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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