简体   繁体   English

ASP.NET MVC 3客户端自定义验证中的jQuery错误

[英]jQuery error in ASP.NET MVC 3 clientside custom validation

I have a razor view in ASP.NET MVC3 application. 我在ASP.NET MVC3应用程序中有剃刀视图。

This view has 2 partialviews 该视图有2个局部视图

  1. PartialView1 is strongly typed and binded with the model. PartialView1被强类型化并与模型绑定。
  2. PartialView2 is not binded with the model. PartialView2未与模型绑定。 and this view consists of a collection of checkboxes. 并且该视图包含复选框的集合。

As part of validation atleast one checkbox must be checked to continue with the save. 作为验证的一部分,必须至少选中一个复选框以继续保存。

Following is the jquery code that is giving me error: Object does not support this property or method. 以下是给我错误的jquery代码:对象不支持此属性或方法。

Error occuring at this line of code: $("#form0").validate({ rules: { issueCheckBox: { selectNone: true}} }); 在以下代码行发生错误:$(“#form0”)。validate({规则:{issueCheckBox:{selectNone:true}}});

Following is the JQuery code: 以下是JQuery代码:

<script src="../../Scripts/jquery-1.4.4.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.validate.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.validate.unobtrusive.min.js" type="text/javascript"></script>          
 <script>
         $.validator.addMethod
            (
                "selectNone",
                function (value, element) {
                    var n = $("input[name='issueCheckBox']:checked").serializeArray();

                    if (n.length < 1) {
                        $("#divIssueCheckBoxError").show();
                        $("#divIssueCheckBoxError").css("color", "red");
                        $("#divIssueCheckBoxError").text("Issue(s) Required. Please select atleast one issue.");
                        return false;
                    }
                    else {
                        $("#divIssueCheckBoxError").hide();
                        return true;
                    }
                },
                function () { }
           );

           jQuery(document).ready(function () {
                    $("#form0").validate({ rules: { issueCheckBox: { selectNone: true}} });
           });
</script>

Does this error only happen in IE9? 仅在IE9中会发生此错误吗? If so, it may just be this jquery ie9 bug related getElementsByTagName. 如果是这样,可能只是与jquery ie9相关的getElementsByTagName 错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM