0

I have an issue and cant seem to resolve it. I have a url, thats like:

myurl/?culture=fr

what I want is

myurl/fr

My Controller looks like :

public ActionResult Index(string culture = null)

and my routeConfig:

routes.MapRoute(
    name: "Languages",
    url: "{controller}/{action}/{culture}"
);

This results in the page isn't redirecting properly. Any hints to solve it?

Saad Farooq
  • 977
  • 2
  • 13
  • 26

1 Answers1

1

Give default Controller and action in your route if you are appending "fr" to the root of the URL(www.yourUrl.com/fr). like this :-

routes.MapRoute(
name: "Languages",
url: "{controller}/{action}/{culture}",
defaults: new { controller = "Home", action = "Index"}

);

Replace "Home" with your default controller and "Index" with default action.

Sombir Kumar
  • 1,841
  • 1
  • 17
  • 30
  • Can you explain more, What should be my routes.MapRoute be? – Saad Farooq Jul 04 '16 at 16:06
  • It doesnt works. it results in page not redirecting properly if used as myurl/Home/Index/fr and Server error if myurl/fr – Saad Farooq Jul 04 '16 at 16:15
  • is your Index action method in Home controller? – Sombir Kumar Jul 04 '16 at 16:18
  • It is working fine at my end. Are you returning right view from action method? or put a break point on action method and check if your parameter have value? if it has value than there is something wrong with return statement in action method. – Sombir Kumar Jul 04 '16 at 16:24
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/116392/discussion-between-sombir-verma-and-saad-farooq). – Sombir Kumar Jul 04 '16 at 16:26