Paul
Paul

Reputation: 3142

ASP.NET MVC Routing for different countries

I have a website that will service a few different countries. When a user hits the site, I'll use an IP locator tool to determine which country they are from. All of the countries will speak English so the views rendered will be the same, however pricing will be different as well as a few other things.

The routing I would want is something like:

You get the idea...

Can anyone provide me with the routing I'll need in the global.asax?

I've tried the following, but I don't want to have to create views for every country:

routes.MapRoute(
"Default", 
"{country}/{controller}/{action}/{id}", 
 new { country = "UK", controller = "Home", action = "Index", id = "" }
 );

Upvotes: 0

Views: 1042

Answers (2)

Remy
Remy

Reputation: 12703

I'm WebForms you can also use

string country = Page.RouteData.Values["country"].ToString();

Not sure if this works for MVC too, but I would assume so.

Upvotes: 0

kdrvn
kdrvn

Reputation: 1009

Your route should be good enough, you simply need to add an argument to your Action methods to retrieve the country value:

public ActionResult Index(int id, string country) {
  // your code here...
}

Upvotes: 2

Related Questions