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?
Asked
Active
Viewed 2,261 times
0
-
how are you validating ? using jQuery unobtrusive validate ? – Shyju Nov 28 '17 at 23:19
-
Yes, I updated the question. – Ricardo Peres Nov 28 '17 at 23:20
-
Take a look at this [unobtrusive validation not working with dynamic content](https://stackoverflow.com/questions/14902581/unobtrusive-validation-not-working-with-dynamic-content) – Shyju Nov 28 '17 at 23:28
1 Answers
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