Validating ASP.NET MVC Client with Partial Views and Ajax

I am using the client validation feature for MVC 2.0 (with Html.ValidationMessageFor()and Html.EnableClientValidation()).

All is well when I use validation in a simple way.

But when I get this form through jQuery Ajax

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

client verification does not work. Why?

+5
source share
3 answers

I had problems with MVC validation and partial views. I sorted it using jquery.validate.js instead of the built-in client check. You can try this.

0
source

jquery.validate( MVC), AJAX, :

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

: jQuery , AJAX

+7

, jQuery JavaScript Ajax?

dataType Ajax,

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

jQuery documentation:

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

, . , jQuery MIME- (XML MIME- XML, 1.4 JSON JavaScript, 1.4 script script, ).

0

All Articles