I want to create routes for rendering views (web routes) and routes for administration purpose (api routes). So I created a directory structure like this:
controllers //root controller folder
ProductController
Api //subfolder of controllers folder
Productcontroller
I have classes with the same name and it is messing up my routes. The "api routes" are overlapping the "web routes".
This is how I defined my api routes
namespace Loja.Controllers.Api
[Produces("application/json")]
[Route("api/Produtos")]
public class ProdutosController : Controller
{
// GET: api/<controller>
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
}
This is how I defined my web routes :
namespace Loja.Controllers
{
public class ProdutosController : Controller
{
[Route("/produtos/{slug}")]
public IActionResult Get(string slug)
When I try to generate a link to my web route I am directed to the api route. Why?
<a asp-controller="Produtos" asp-action="Get" asp-route-slug="@produto.Slug">
When I click the link I am directed to
http://localhost:5000/api/produtos?slug=assadeira-grande-40-x-27-cm-109dcc