Home Multilingual attribute routing
Reply: 0

Multilingual attribute routing

MiP
1#
MiP Published in 2017-12-07 17:50:12Z

How can I use different languages for attribute route in ASP.NET Core/MVC?

For example, I have a User Controller that can edit user information:

[Route("user")]
public class UserController : Controller {
    [HttpGet("edit/{id}/{username}")]
    public IActionResult Edit (int id) {
        return ...;
    }
}

What can I do to support more languages? I want the server to generate links that depend on the language the user is choosing:

@{ var user = ...; }
<a asp-controller="User"
   asp-action="Edit"
   asp-route-id="@user.Id"
   asp-route-username="@user.Username">
    Edit
</a>

// The code above will generate
English link => <a href="/user/edit/1/smith">Edit</a>
Spanish link => <a href="/usuario/editar/1/smith">Editar</a>
etc...
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.335871 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO