search

Home  >  Q&A  >  body text

c# - How to bind jQuery.validate.js verification to a dynamically added form

How to bind jQuery.validate.js verification to a dynamically added form
Can you help me a lot

漂亮男人漂亮男人2782 days ago766

reply all(2)I'll reply

  • 给我你的怀抱

    给我你的怀抱2017-05-16 17:07:39

    If you are using asp.net mvc and use jquery.validate.unobtrusive.js (asp.net mvc’s own validation, something that can be used in combination with class features)

    Then you just add this js code before loading the page

        //动态表单验证
        $(document).ajaxComplete(function () {
            $.validator.unobtrusive.parse(document);
        });

    reply
    0
  • PHPz

    PHPz2017-05-16 17:07:39

    Is your form id predictable? If so, just write it in js:

    $("#demoForm").validate();
    

    That’s it. If even the ID is dynamically generated, just call the generated id directly in the view:

    $("@ViewBag.FormId").validate();
    

    reply
    0
  • Cancelreply