I want to make a simple multilingual web application using routes.
What I want to do in the URL:
ru / products and
he / Prodotti
with the same action.
I created two different routes with one action / controller:
routes.MapRoute(
name: "english",
template: "en/products",
defaults: new { controller = "home", action = "products" }
);
routes.MapRoute(
name: "italiano",
template: "it/prodotti",
defaults: new { controller = "home", action = "products" }
);
When I want to call one of these routes, I use:
<a href="@Url.RouteUrl("english", new { Action = "home", Controller = "products"})">Products</a>
<a href="@Url.RouteUrl("italiano", new { Action = "home", Controller = "products"})">Prodotti</a>
And I get url ru / products or
he / Prodotti
The problem is that when I want to create a message in the form, I cannot control which url will be returned.
<form asp-action="products" method="post">
This one only returns the first value of my routes.
The question is , how can I manage my routes when submitting the form, how do I do it with the Url.RouteUrl link?
, :
[Route("it/prodotti")]
[Route("en/products")]
public ViewResutl products() {
...
return View(new viewmodel...);
}