CrazyLegs
CrazyLegs

Reputation: 608

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:

enter image description here

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?

Upvotes: 0

Views: 179

Answers (1)

Jonas Høgh
Jonas Høgh

Reputation: 10874

Remove the braces around {business} in your route template. Business is a constant string, not a route parameter:

[Route("business/{url}")]

Upvotes: 2

Related Questions