Click here to Skip to main content
14,882,311 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)

In form post method in MVC view,
if validation fires then loader should not come and dispaly only validations
else no validations fire then loader should come and save the data.

how can I do it?


What I have tried:

placed loader on form submit in javascript and disbale the button.

$("#frmContact").submit(function (e) {
        $(".loading").css("display", "inline");

1) loader : Issue is that if validation fires, then loader also come alongwith validations and then need to reload the page and input data.

2) Disable Submit button : If I disable the Submit button on click and if validation fire then after button remains the disable instead enable. So if validation is there then enable the button and if validations are not fire then disable the button.

all this to avoid the duplicate entry as if button enables then if user clicks on submit
Updated 11-Dec-16 20:04pm

1 solution

you can check like that in javascript if form is not valid then fire the validation if form is properly filled then u can show the loader as below in MVC.
var $valid = $("#frmFields").valid();
if (!$valid) {
       $(".loading").css("display", "inline");
       return false;
 else {
      $(".loading").css("display", "inline");
      return true;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900