I'm trying to create a very specific route on a page of my project.
As usual, the routes in .NET are controller/action/id
but in a specific page I would like it to be controller/id/action
.
What I got was:
routes.MapRoute(
name: "Produto",
url: "Produto/{name}/{action}",
defaults: new { controller = "Produto", action = "Index" },
constraints: new { name = @"^[a-z\.]{3,20}$" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
constraints: new { controller = @"^((?!Perfil).*)" }
);
So, the url / Product / car / View works perfectly. The url / Campaign / Edit / 1 also works perfectly.
However , if you call the url / Product / car (WITHOUT BAR IN FINAL) is not working. It is not going to action index. I tried to use the code below, but it did not work.
routes.MapRoute(
name: "ProdutoIndex",
url: "Produto/{name}",
defaults: new { controller = "Produto", action = "Index" },
constraints: new { name = @"^[a-z\.]{3,20}$" }
);
I would like it to work without the slash at the end, because forcing the user to put this bar is very bad.