Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

263
Views
Close modal on AJAX Sucess(ASP.NET MVC)

I have Modal in view for making new record in Database.

View for it in Partial View

Here is code of view

<script src="~/Scripts/jquery-3.1.1.js"></script>

For AJAX I using this code

<script>
   $(document).ready(function () {
       $('#save_quest').click(function () {
        savequestion();
    });
});
    function savequestion() {
        $.ajax({
            type: 'Post',
            dataType: 'Json',
            data: {
                Question_new: $('#question').val(),
                Answer: $('#answer').val(),
                Preparing: $('#prepare').val(),
                Retries: $('#retries').val(),
                  },
            url: '@Url.Action("CreateNewQuestion", "Questions")',
            success: function (da) {
                if (da.Result === "Success") {
                    $('#myModal').modal('hide')
                    //window.location.href = da.RedirectUrl;

                } else {

                    alert('Error' + da.Message);
                }
            },
            error: function (da) {
                alert('Error');
            }
        });
    }

I need to hide modal when AJAX call is Successful

I try this $('#myModal').modal('hide')

Here is my modal on Primary View

<div class="modal fade" id="myModal" role="dialog" data-backdrop="false">
<div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4 class="modal-title">Modal Header</h4>
        </div>
        <div class="modal-body">
            @Html.Partial("~/Views/Questions/CreateQuestion.cshtml")
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
    </div>

</div>

How I can hide it on AJAX Success?

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

You can try any of the below option in your ajax success block. Hopefully it will solve your problem.

        $("#myModal").modal('hide');
    OR
        $('#myModal').modal('toggle');
    OR
        $('#myModal').removeClass('show');
    OR
        $('#myModal').modal().hide();
    OR
        $("#myModal .close").click();
    OR
        $("#myModal .close").trigger("click");
about 4 years ago · Santiago Trujillo Report

0

I found solution

Just need to write

$('#myModal').hide();

about 4 years ago · Santiago Trujillo Report

0

This is not the proper way. $('#myModal').hide();

The proper way $("#myModal").modal('hide');

Have you try adding bootstrap.js in your page? if not please include it in your page and then test. It should work.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!