views:

125

answers:

2

Hello,

I'm using 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 works.

A: 

Maybe jquery isn't evaluating the javascript on the ajax response ?

Try using dataType property on the ajax call

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

From jQuery docs:

dataType Default: Intelligent Guess (xml, json, script, or html)

The type of data that you're expecting back from the server. If none is specified, jQuery will intelligently try to get the results, based on the MIME type of the response (an XML MIME type will yield XML, in 1.4 JSON will yield a JavaScript object, in 1.4 script will execute the script, and anything else will be returned as a string).

Rafael Mueller
Rafael Mueller, thank you for your answer, but it's doesn't help me.I have included alert('scripts test') into my partial view - it works. But I still have a problems with validation.
griZZZly8
A: 

I've had problems with MVC validation and partial views too. I sorted it out by using jquery.validate.js instead of the build-in client-validation. You can try that out.

korchev
jQuery.validate can't see my model. I want to define validation rules in model classes.
griZZZly8
You can do so. Check the ASP.NET MVC Futures http://aspnet.codeplex.com/releases/view/41742
korchev