2

my current url is something like this => http://localhost:4330/Restaurants/?Location=Manchester&Cuisine=0&NetProfit=0&Turnover=0&MaxPrice=120000&SortPriceBy=Low&Page=0

i want it to make something like this => http://localhost:4330/Restaurants/Manchester/?Cuisine=Chinese&MaxPrice=120000

Where Param Query string that doesnt have values (0) will not be included on query string URL Is it possible?

1
  • if you want to hide certain parameter from showing as querystring then you can just pass them via other methods, i.e. form values. Commented May 23, 2011 at 9:01

2 Answers 2

5

UPDATED

stringAdd this to Global.asax routes

 routes.MapRoute( "Name of route", // Route name "Restaurants/{cityid}/", // URL with parameters new { controller = "Restaurants", action = "Index" } // Parameter defaults ); 

This is controller:

public ActionResult Index(string city, int cuisine = 0, int ChineseMaxPrice=0) { Return View(); } 

Like int cuisine = 0 - this set the default value to parameter if this parameter is not set in querystring

string city - is a parameter that should be in string (not optional)

Sign up to request clarification or add additional context in comments.

2 Comments

Isn't that route a double wildcard? it matches any controller that has any action..? Or is the new clause where you are specifying the specific controller and action?
sorry, i made a small mistake/ updated. This is additional route
1

Try adding add the corresponding route:

routes.MapRoute( "Restaurants", "Restaurants/{city}", new { controller = "Restaurants", action = "Index", city = UrlParameter.Optional } ); 

which would map to the Index action on the Restaurants controller:

public ActionResult Index(string city) { ... } 

Comments