.Net Core Multi-Language Routing

asp.net-core, asp.net-core-mvc, c#, routes

Solution

Great news, finally i have found the answer.

    @using (Html.BeginRouteForm("routenamehere"))
    {
    <form>
    ...
    ...
    </form>
    }

Problem

I want to do a simple multi-language web app with routes. What I want to do is in the url: en/products and it/prodotti with the same action. I have created two differend routes with same 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 theese 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 en/products or it/prodotti The problem is, when I want to make a form post, I cannot control which url is going to return. ``` <form asp-action="products" method="post"> ``` This only returns the first value of my routes. The question is, how can I control my routes when I sending a form like I'm doing with Url.RouteUrl link? I tried this but this also not works: ``` [Route("it/prodotti")] [Route("en/products")] public ViewResutl products() { ... return View(new viewmodel...); } ```

Original source