Click here to Skip to main content
15,889,096 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hello,

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?

Thanks,
KK

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
Posted
Updated 11-Dec-16 20:04pm
v2

1 solution

Hi,
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.
C#
$.validator.unobtrusive.parse($('#frmFields'));
var $valid = $("#frmFields").valid();
if (!$valid) {
      $validator.focusInvalid();
       $(".loading").css("display", "inline");
       return false;
  }
 else {
      $(".loading").css("display", "inline");
      SaveAccount();
      return true;
   }
});
 
Share this answer
 

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