Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

419
Vistas
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 Respuestas
Responde la pregunta

0

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

to

[Route("/search")]

it's worked

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda