在基于asp.net mvc验证属性的工具提示jquery插件中显示错误

时间:2011-08-27 08:04:40

标签: asp.net-mvc asp.net-mvc-3 jquery-validate

我想在工具提示中显示jquery错误,如下图所示:

enter image description here

有一些jquery插件可以做到这一点: http://www.position-relative.net/creation/formValidator/demos/demoValidators.html http://validity.thatscaptaintoyou.com/

但它们并不适用于asp.net mvc 3.0验证属性。 有没有类似的插件可以做到这一点?或者我能做些什么来显示工具提示中的错误?

1 个答案:

答案 0 :(得分:1)

我们使用Jquery验证插件做了类似的事情。为此,我们最初必须创建弹出窗口。

Javascript Fn

$("#formID").validate({
        submitHandler: function (form) {
            CallFunction();
        },

        highlight: function (element, errorClass) {
            HidePopup(element);
            ShowPopup(element);
        },

        unhighlight: function (element, errorClass) {
            HidePopup(element);
        },

        errorElement: "span",

        errorPlacement: function (error, element) {
            error.appendTo(element.prev("label"));
        },

        rules: {
           txtName:"required"
        }
});

function ShowPopup(paramElement)
{
    //function to show popup and position div accordingly
    $('#div'+paramElement.Id).show();
}

function HidePopup(paramElement)
{
    //function to hide popup
    $('#div'+paramElement.Id).hide();
}



**Html**


<form id="formID" action="">

    <input name="txtName" type="text" id="txtName" />
    <div id="divtxtName" >Please enter name</div>

</form>
相关问题