<meta name="viewport" content="width=device-width" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.bundle.min.js" integrity="sha384-LtrjvnR4Twt/qOuYxE721u19sVFLVSA4hf/rRt6PrZTmiPltdZcI7q7PXQBYTKyf" crossorigin="anonymous"></script>
<script type="text/javascript">
$(document).ready(function () {
$(".deleteUserAccount").click(function (e) {
//fixed the following line
$(".btn-yes4").click(function () {
var holdUserName = $('#UserName').val();
var holdPassword = $('#Password').val();
$("#myModal4").modal("hide");
url: '@Url.RouteUrl(new{ action="DeleteUserAccount", controller="Home"})',
data: { userName: holdUserName, password: holdPassword },
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
success: function (data) {
$("#errorMessage").css("display", "block");
$("#errorMessage").css("display", "none");
$("#errorMessage").text(data);
error: function (xhr, ajaxOptions, thrownError) {
alert('Critical Error: something is wrong in the call to DeleteUserAccount for delete! Status: ' + xhr.status + '. Error: ' + thrownError.toString() + '. Response Text: ' + xhr.responseText);
$(".btn-no4").click(function () {
$("#myModal4").modal("hide");
//$("#myModal4").on('hidden.bs.modal', function () {
// $("#myModal4").remove();
<div class="login-panel">
@*took out condition, and started with style none*@
@*@if (ViewBag.errormessage != null)
<p class="alert alert-danger" id="errorMessage" style="display:none">@ViewBag.errormessage</p>
<div class="col-md-12 col-xs-12">
<h4 class="verify"><strong>I will need to verify your identity in order to delete your account.</strong></h4>
<h4 class="verify"><strong>Please provide the following:</strong></h4>
<div class="col-md-12 col-xs-12">
<label class="manadatory" for="UserName">User Name</label>
<input id="UserName" type="text" value="" name="UserName">
<div class="col-md-12 col-xs-12">
<label class="manadatory" for="Password">Password</label>
<input id="Password" type="text" value="" name="Password">
<div class="col-md-offset-0 col-md-10">
<input class="btn btn-primary deleteUserAccount" value="Delete Account">
@Html.ActionLink("Cancel", "Index", "User", null, new { @class = "btn btn-info" })
<div class="modal fade" id="myModal4" role="dialog" display="none">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body" style="padding:10px;">
<h4 class="text-center">Are you sure you want to permanently delete your account and all it contains? Continue ?</h4>
<div class="text-center">
<a class="btn btn-info btn-yes4">Yes</a>
<a class="btn btn-default btn-no4">No</a>