I had the same problem and solved it.
Open MicrosoftMvcJQueryValidation.js and make the following changes.
Add this function
function __MVC_ApplyClientValidationMetadata() { var allFormOptions = window.mvcClientValidationMetadata; if (allFormOptions) { while (allFormOptions.length > 0) { var thisFormOptions = allFormOptions.pop(); __MVC_EnableClientValidation(thisFormOptions); } } }
Find $ (document) .ready () and replace it with
$(document).ready(__MVC_ApplyClientValidationMetadata);
Now just do the following
If you use html (), just call __MVC_ApplyClientValidationMetadata after loading the html into the element.
$("#someDiv").html(responseHtml); __MVC_ApplyClientValidationMetadata();
If you use load (), another problem arises. It removes all script tags. So you need to do something like the following.
$("#someDiv").load("/a/partialview/request" , function(response){ var scripts = $(response).filter("script"); for (var i = 0; i < scripts.length; i++) {
One more thing. Make sure the forms you upload using ajax have a unique identifier. By default, all forms receive a form identifier.
jcruz
source share