1

i work at a MVC application and i want to make url's more friendly. i was trying to do that using routes but at some url's it doesn't work.

i want a url like http ://localhost:55696/fr/Pages/Lists?pageType=PropertiesList&list=Market to become http: //localhost:55696/fr/(market_in_french)

I was trying with

routes.MapRoute(
    name: "MarketFr",
    url: UrlStrings.ResourceManager.GetString("Market", new CultureInfo(CultureEnum.fr.ToString())),
    defaults: new {controller = "Pages", action = "Lists"}
);

but the result is http://localhost:55696/fr/market?pageType=PropertiesList&list=Market

how can I solve this. The Lists method is defined like this:

public ActionResult Lists(string pageType, string list = "", string viewType = "")

i made the changes:

routes.MapRoute(
                name: "MarketFr",
                url: UrlStrings.ResourceManager.GetString("Market", new CultureInfo(CultureEnum.fr.ToString())),
                defaults: new { controller = "Pages", action = "Lists", pageType = "PropertiesList", list = "Market", viewType = "" }
                );

now it doesn't work at all, my url is like at the begining: http://localhost:55696/en/Pages/Lists?pageType=PropertiesList&list=Market

if I type in the address bar http://localhost:55696/fr/market it lands me to the right page, but when i click the button linked to the

Url.Action("Lists", "Pages", new { pageType = PageTypesEnum.PropertiesList, list = PropertyListViewMode.Market })

in the address bar the url is http://localhost:55696/en/Pages/Lists?pageType=PropertiesList&list=Market

Cœur
  • 37,241
  • 25
  • 195
  • 267
RemusCoder
  • 11
  • 2

2 Answers2

0

Not clear how you generate such url, so assuming something like Url.Action. For particular case you have specifying all defaults should produce url you like:

    url: "fr/market",    
    defaults: new {controller = "Pages", action = "Lists", 
                   pageType="PropertiesList", list= "Market"}
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
0

You have spaces in that URL. Space characters are not allowed.
Replace each space with %20 in your url:

http ://localhost:55696/fr/Pages/Lists?pageType=PropertiesList&list=Market%20to%20become%20http://localhost:55696/fr/(market_in_french)
Community
  • 1
  • 1