简体   繁体   English

Asp.Net MVC仍在验证隐藏

[英]Asp.Net MVC Still validating hidden

I'm using 我正在使用

   $(document).ready(function () {
    $(":radio:eq(1)").click(function () {
        $("#JointApplicantInfo").show(1000);
    });

    $(":radio:eq(0)").click(function () {
        $("#JointApplicantInfo").hide(1000);
    });

});

to hide a div but when hidden the validations from 隐藏一个div,但是当隐藏来自

src="~/Scripts/jquery.validate.min.js">

src="~/Scripts/jquery.validate.unobtrusive.min.js">

are still happening even when hidden. 即使隐藏也仍然在发生。

I am using [required] tags in the model to cause validation to happen. 我在模型中使用[required]标签来导致验证发生。

I am unsure of how to make this not happen. 我不确定如何避免这种情况的发生。 I understand that it requires more scripting, but I am a novice and cannot figure it out. 我知道它需要更多脚本,但是我是新手,无法弄清楚。

You can override the jQuery validation and tell it to ignore hidden fields: 您可以覆盖jQuery验证,并告诉它忽略隐藏字段:

$(function() {
    var settngs = $.data($('form')[0], 'validator').settings;
    settings.ignore = ":not(:visible)";
});

Reference 参考

Edit: I should add though, as others have commented, it is not really correct to annotate a field as [Required] if it is only required under certain circumstances. 编辑:我应该补充一点,正如其他人所评论的那样,如果仅在某些情况下需要将字段注释为[Required] ,这是不正确的。

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

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