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

418
Views
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 answers
Answer question

0

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

to

[Route("/search")]

it's worked

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