Saad Farooq
Saad Farooq

Reputation: 997

Convert Query string to Route Path

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?

Upvotes: 0

Views: 373

Answers (1)

Sombir Kumar
Sombir Kumar

Reputation: 1891

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.

Upvotes: 1

Related Questions