Adding validation with MVC 3 & jQuery Validator in execution time

前端 未结 2 1529
梦毁少年i
梦毁少年i 2020-12-23 15:30

I have a form with validation rendered by c# when the page is loaded, the rendered fields like so:



        
相关标签:
2条回答
  • 2020-12-23 15:50

    I solved here using

    jQuery.validator.unobtrusive.parseElement($("#element")[0], false);
    $.validator.unobtrusive.parseDynamicContent($("#element")[0]);
    

    parseDynamicContent I got here

    0 讨论(0)
  • 2020-12-23 15:58

    Feels like a bit of a hack, but here's how I've done it.

    // Target Form
    var $form = $("**form selector**");
    
    // Unbind existing validation
    $form.unbind();
    $form.data("validator", null);
    
    // Check document for changes
    $.validator.unobtrusive.parse(document);
    
    // Re add validation with changes
    $form.validate($form.data("unobtrusiveValidation").options);
    

    Rich

    0 讨论(0)
提交回复
热议问题