Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Confirm Delete in unobtrusive ajax is not working

I have this form:

<form data-ajax="true" data-ajax-method="post"  
    data-ajax-url="@(Url.Action("DeleteUserModel", "AccountAdmin"))"
    data-ajax-mode="replace" data-ajax-update="#deleteDiv"
    data-ajax-loading="#ajax" data-ajax-failure="failed"
    data-ajax-success="ondeletesuccess">
     <input type="hidden" name="userName" value="@user.UserName" />
     <input type="submit" class="btn btn-danger" onclick="ConfirmDelete"
            value="Delete" />
 </form>

and the javascript in the main page:

<script>
  function ConfirmDelete() {
      var result = confirm("Are you sure to delete?");
      if (!!result) {
          return true;
      }
      return false;
  }
</script>

But the form deletes the record without showing confirmation. how to correct this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Replace "ConfirmDelete"in your code with function "ConfirmDelete()" defined as…

function ConfirmDelete() {
      var result = confirm("Are you sure to delete?");
      if (!!result) {
          return true;
      }
      return false;
  }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading