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

429
Visualizações
Asp.Net Core - How to set the UrlAction in Controller?

I have an input box to search ...

Html :

<form id="searchForm" asp-controller="Product" asp-action="SearchProduct" method="get">

This input performs search in two ways:

1- After pressing the Enter key 2- After the click on the "a" tag

In the first step, the address is displayed in the image below : enter image description here

In the second step, the address is displayed in the image below : enter image description here

After searching again, the address is displayed in the image below enter image description here

JavaScript :

 $('.txt-search-story').click(function () {
    var span = $(this).find('span');
    var txtspan = span.text();

     $.ajax({
         url: "/Product/GetTextSearch",
         type: 'Get',
         data: { "q": txtspan },
         success: function (response) {
             window.location.href = response.redirectToUrl;
         }
    });
});

Controller one :

[Route("/search/{**q}")] 
public async Task<IActionResult> SearchProduct(string q, int page = 1)
    {
        if (q != null)
        {                
            var searchProduct = await _product.SearchProduct(q, skip, countproduct);
            ViewBag.searchtext = q;

            return View(searchProduct);
        }                    
    }

 

Controller two for Ajax:

 public IActionResult GetTextSearch(string q)
    {
        return Json(new { redirectToUrl = Url.Action("SearchProduct", "Product", new { q = q }) });
    }

I want the second address to be like the first address What should I do?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

thanks @daremachine - I changed [Route("/search/{**q}")]

to

[Route("/search")]

it's worked

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