I have a Button on my razor page that retrieves input OnPost( ). If the inputs are update into database successful, I need to show a Modal that shows the success message and redirect to another page a few seconds later.
<section class="m-t2 m-b4">
<form method="post">
//Codes here
//....
<button type="submit" class="btn btn-danger">
Reject
</button>
</div>
</div>
</form>
</section>
<!-- Modal -->
<div class="modal" tabindex="-1" role="dialog" id="UpdateSucessModal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Modal Title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
Modal Body
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
function OnPostReponseModal() {
$('#UpdateSucessModal').modal('show');
// Wait for 3 seconds, then redirect to the new page
setTimeout(function () {
window.location.href = '/Stage3/Index';
}, 2000); // 2000 milliseconds = 3 seconds
}
public void OnPost()
{
// retrieve some input from from using Request.Form
EnvelopeModel model = new EnvelopeModel();
// Dummy data assuming update is successful
// _envelope.Update(envelopeModel)
bool isUpdateSuccess = true;
if (isUpdateSuccess) {
// Call the JavaScript function to show the modal and redirect after a few seconds
}
else {
Response.Redirect("/Unsuccessful");
}
}