0

I have some dynamic content that is loaded by AJAX and added to the current page. This content is essentially a form that is rendered on the server-side which includes client-side validation attributes. The problem is, when the resulting form is validated using unobtrusive validation - the original plus the dynamic, AJAX-loaded -, the validation on the form part that came from AJAX does not fire. Is it possible to include it in the client validation?

Ricardo Peres
  • 13,724
  • 5
  • 57
  • 74

1 Answers1

1

The solution was to do:

//add content to the form
$(form).removeData("validator").removeData("unobtrusiveValidation");
$.validator.unobtrusive.parse(form);

There is documentation from Microsoft available at https://learn.microsoft.com/en-us/aspnet/core/mvc/models/validation#client-side-validation, but it has a small error, on which the removeData method is being called on the form element instead of the jQuery wrapping it.

Ricardo Peres
  • 13,724
  • 5
  • 57
  • 74