Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show loading icon after submiting the form but not in case the Model is not valid in ASP .NET MVC

I want to show a loading-icon after submitting the form, but not if the View Model is not valid (I mean jQuery MVC validation).

        <input type="submit" class="btn btn-default" value="Register"/>
        <div class="work-con"></div>

If I use something like this

    $("#myform").submit(function (event) {
        // Animate loader
        $(".work-con").fadeIn("slow");
    });

it works fine, but it shows the icon even if the Model is not valid and the warnings are displayed.

like image 791
Petr Avatar asked Apr 22 '15 10:04

Petr


1 Answers

MVC uses jQuery validation. You can use that to check if the form is valid:

$("#myform").submit(function (event) {

    var isValid = $('#myForm').valid();
    if (isValid) {    
        // Animate loader
        $(".work-con").fadeIn("slow");
    }
});
like image 68
CodeCaster Avatar answered Oct 19 '22 03:10

CodeCaster