Reputation: 2391
I have a controller in my ASP.NET Webb app that should display search results when I search like this..
Cases/Search/Volvo
In this case Volvo
is the string that I searched for.
It currently work when searching like this..
Cases/Search?q=volvo
How should my routing look like for this to work?
Upvotes: 2
Views: 2869
Reputation: 247163
You can consider using Attribute routing
[Route("[controller]"]
public class CasesController : Controller {
//Matches GET cases/search/volvo
[HttpGet]
[Route("search/{q}")]
public IActionResult Search(string q) {
//...code removed for brevity
}
}
Reference Routing to Controller Actions
Upvotes: 3