3

here is question. I have an localized asp.net mvc website. Localization done by next steps: 1. for each route I automatically add an {culture} url segment with default value to "ru".

I want my urls to be with culture only for foreign cultures. For example:

http://mysite.com/ua/contacts - ukrainian
http://mysite.com/fr/contacts - francis
http://mysite.com/contacts - russian

I can't arrive this, because @Url.Action method always returns url with culture, even then it is a default culture. Help me please!

tereško
  • 58,060
  • 25
  • 98
  • 150
Ilya
  • 51
  • 3
  • Can you show us your route configuration? – Fenton Apr 17 '13 at 08:46
  • `routes.MapRoute( name: "HomePage", url: "{culture}/{controller}/{action}", defaults: new { controller = "Home", action = "Index", culture="ru" } );` – Ilya Apr 17 '13 at 10:13
  • Add `culture` as an optional parameter `culture= UrlParameter.Optional` – Saanch Apr 17 '13 at 10:21
  • If you set culture=UrlParameter.Optional then you will not be able to access home page. As I see it is a very generic situation but I can't find any info about how to implement that, using standart ASP.NET MVC. – Ilya Apr 17 '13 at 10:26
  • @Ilya answered your another question similar to this. Take a look, http://stackoverflow.com/questions/16103621/asp-net-mvc-routing-and-url-building/16125500#16125500 – shakib Apr 23 '13 at 05:05

1 Answers1

0
 routes.MapRoute(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
            );

as base you can find solution right here
http://www.asp.net/mvc/tutorials/older-versions/controllers-and-routing/asp-net-mvc-routing-overview-cs and on msdn
http://msdn.microsoft.com/en-us/library/cc668201(v=vs.100).aspx

Roar
  • 2,117
  • 4
  • 24
  • 39
  • 1
    Greate ) Can you show me please where is answer on that pages? – Ilya Apr 17 '13 at 10:12
  • cannot try right now but direction should be like this routes.MapRoute( "Default", // Route name "{controller}" + MakeSomeLogic + "/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = "" } // Parameter defaults ); routes.MapRoute( "Default2", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = "" } // Parameter defaults ); – Roar Apr 17 '13 at 12:30