How to show a loading icon after submitting a form but not when the model is invalid in ASP.NET MVC

I want to show the loading icon after submitting the form, but not if the viewmodel is invalid (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 shows the icon even if the model is invalid and warnings are displayed.

+3


source to share


1 answer


MVC uses jQuery validation. You can use this to check if a form is valid:



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

    var isValid = $('#myForm').valid();
    if (isValid) {    
        // Animate loader
        $(".work-con").fadeIn("slow");
    }
});

      

+4


source







All Articles