I have an ASP.NET MVC 4 App that uses the jQuery.validation.js and MVC jQuery.validation.unobtrusive.js plugin . I use data annotations in my view model to validate text box input as a whole.
This (nested) view is loaded in the parent view using ...
<% Html.RenderPartial("New"); %>
One of the first downloads on the first page, client-side validation works. But any reloading of a nested view using an ajax call, client-side validation no longer works. Why is this?
Update : (sample code from web developer solution below)
$.validator.unobtrusive.parse($('form'));
Example:
var saveAndUpdate = function (url) { var myForm = $('form', $('#TheDivThatContainsTheNewHTML')); $.ajax({ url: url, type: 'POST', data: myForm.serialize(), success: function (result) { $('#TheDivThatContainsTheNewHTML').html(result); $.validator.unobtrusive.parse($('#TheDivThatContainsTheNewHTML')); }, error: function (xhr, ajaxOptions, thrownError) { alert(xhr.status); alert(thrownError); }, dataType: 'html' }); }
duyn9uyen
source share