'In a C# ASP.NET Core 3.1 application how do I route to a controller then query string?
I have a view setup as:
I then have my Business controller:
[Route("{business}/{url}")]
public IActionResult business(string url)
{
return View();
}
My aim is to be able to pass the url string 'neatly' like so
https://website.com/business/business-name-123
The business-name-123 is then received as the parameter.
I have created something similar to this before where you pass ?query=website-name but I don't want this, can someone explain what I need to do to get this working using just the / routing aspect?
Solution 1:[1]
Remove the braces around {business} in your route template. Business is a constant string, not a route parameter:
[Route("business/{url}")]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jonas Høgh |

