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

116
Visualizações
calling controller method using jquery but method not redirecting to its corresponding view

I have a page "GetData.cshtml" where I need to fill up some textbox data and send to the controller method. I am using jquery to send data to the controller method.

//GetData.cshtml
$(document).ready(function () {
    $('#btn_sbmt_recommendation').click(function () {            
        $.post("/RegistrationModels/Registration_card",
        {
            firm_id: $('#id_reg_id').val(), 
            amount: $('#id_amount').val()
            });
        console.log("job done....");
    });
})

While debugging the app, the controller method is called successfully.

public ActionResult Registration_card(string reg_id, string amount)
        {
            try
            {
                // code block
                return View(updated_firm);
            }
            catch (Exception ex) { throw; }
        }
    

As my requirement, I want to display the data in Registration_card.cshtml page, but it is not redirecting to the page. The console message console.log("job done...."); in the jquery block is showing. It means the page is again back to GetData.cshtml. Is it due to using jquery to call controller method? How can I go to page Registration_card.cshtml after calling the controller method Registration_card via jquery.

I also tried with the below code, but it is also not working.

public ActionResult Registration_card(string firm_id, string ward_calani_num, string amount)
        {
            try
            {
                // code block
                return RedirectToAction("Registration_card", updated_firm);
            }
            catch (Exception ex) { throw; }
        }
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

According to your question, it seems you want to redirect/go to the Registration_card.cshtm from GetData.cshtml by taking some data from the GetData.cshtml to the Registration_card ActionMethod which will actually show the Registration_card.cshtm.

If the above scenario is true, then you do not need to Ajax Post request as your ActionMethod is HttpGet as you do not specify it is as HttpPost. So the workaround can be something like the below code.

$(document).ready(function () {
    $('#btn_sbmt_recommendation').click(function () {
        var id_reg_id=$('#id_reg_id').val();   
        var id_amount=$('#id_amount').val();         
        location.href=`/RegistrationModels/Registration_card?reg_id=${id_reg_id}&amount=${id_amount}`;
      
        //$.post("/RegistrationModels/Registration_card",
           //    {
           //        firm_id: $('#id_reg_id').val(),
           //        amount: $('#id_amount').val()
           //    });
          //console.log("job done....");
    });
})
about 4 years ago · Juan Pablo Isaza Relatório

0

If want to redirect page you should use javascript or jquery because when you use jquery then controller not working for redirect.

about 4 years ago · Juan Pablo Isaza 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