Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

273
Visualizações
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?

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

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");
over 4 years ago · Santiago Trujillo Relatório

0

I found solution

Just need to write

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

over 4 years ago · Santiago Trujillo Relatório

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.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda