ASP.NET MVC 2 Client Validation Function in Ajax Form

My problem is this:

I am using the client validation feature in MVC 2.0.

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

But when I use the Ajax form and update the fields of the ajax form, client validation does not work.

I think I need to update the check after ajax call, but I don't know how to do this.

Can anybody help me?

+3
source share
2 answers

, window.mvcClientValidationMetadata "", jQuery mvc. jquery, ajax.begin. :

<div id="result"></div>

<% Html.EnableClientValidation(); %>

<% using (Ajax.BeginForm(new AjaxOptions { UpdateTargetId = "result" }))

// here goes the form
<input type="submit" value="Create" />
<% } %>

this is the required code that needs to be added:


<script type="text/javascript">


function RefreshClientValidationMetadata() {
    var allFormOptions = window.mvcClientValidationMetadata;
    if (allFormOptions) {
        while (allFormOptions.length > 0) {
            var thisFormOptions = allFormOptions.pop();
            __MVC_EnableClientValidation(thisFormOptions);
        }
    }
}

RefreshClientValidationMetadata();

</script>

, RefreshClientValidationMetadata() ​​ .

!

0

:

$(document).ajaxComplete(function () {
   $.validator.unobtrusive.parse(document);             
});
0

Source: https://habr.com/ru/post/1737900/


All Articles