Multi-lingual websites with ASP.NET MVC

The URL can take almost any other form you like. For more info, check ASP.NET MVC Framework (Part 2): URL Routing. Just for starting (since I am not sure if it is the optimum solution), you can add two new routes in your global.asax:

        routes.MapRoute(
            "ukRoute",
            "{lang}/Products/{action}/{id}/{subcategory}",
            new { lang = "uk", controller = "Products", action = "Index", id = "", subcategory = "" }
        );
        routes.MapRoute(
            "esRoute",
            "{lang}/Productos/{action}/{id}/{subcategory}",
            new { lang = "es", controller = "Products", action = "Index", id = "", subcategory = "" }
        );

These routes understand the following URLs (and map both of them to the ActionResult Category(string id, string subcategory) method of ProductsController):

uk/Products/Category/1/A
es/Productos/Category/1/A

If you want to create such URLs in your views you can use something like:

<%= Html.RouteLink("English 1.A", "ukRoute", new { lang = "uk", action = "Category", id = "1", subcategory = "A" })%>
<%= Html.RouteLink("Spanish 1.A", "esRoute", new { lang = "es", action = "Category", id = "1", subcategory = "A" })%>

Leave a Comment