Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC client validation with partial views and Ajax

I'm using the client validation function of the MVC 2.0 framework (with Html.ValidationMessageFor() and Html.EnableClientValidation()).

Everything is nice, when I use the validation in a simple form.

But when I get this form via jQuery Ajax

$.get('PathToMyForm', function(htmlResult) {
    $('selector').html(htmlResult);
});

client validation doesn't work. Why?

like image 847
griZZZly8 Avatar asked Apr 19 '10 11:04

griZZZly8


1 Answers

If you are using jquery.validate (particularly with MVC) and you are loading pages via AJAX, you need to make the following call after the page loads:

$.validator.unobtrusive.parse($("#validation"));

See more at my blog post: Using Unobtrusive jQuery Validation with Forms Loaded via AJAX

like image 137
JasCav Avatar answered Sep 28 '22 04:09

JasCav