Manually bind JQuery validation after Ajax request

前端 未结 5 1374
轮回少年
轮回少年 2021-01-03 02:27

I\'m requesting an ASP.net MVC view into a live box and the view contains form fields that have been marked up with attributes to be used by JQuery\'s unobtrusive validators

5条回答
  •  不知归路
    2021-01-03 03:05

    For some reason I had to combine bjan and dfortun's answers...

    So I put this in my view:

    @{
      this.ViewContext.FormContext = new FormContext();
    }
    

    And this execute this after the ajax call finishes:

    var form = $("#EnrollmentForm");
    form.unbind();
    form.data("validator", null);
    $.validator.unobtrusive.parse(document);
    form.validate(form.data("unobtrusiveValidation").options);
    

提交回复
热议问题