Reputation: 3
I get error when paging,
my actions:
ProductList(string country, string city, string town, int? pageNumber)
my Route:
routes.MapRoute(
"ProductList",
"myList/{country}/{city}/{town}/{pageNumber}",
new { controller = "Product", action = "ProductList", country="", city="", town= "", pageNumber = UrlParameter.Optional });
Action Link:
Url.Action("myList","Product", new{ country="Finland",city="",town="",pageNumber=2 })
city = 2 ??
I've found a solution as follows:
Url.Action("myList","Product", new{ country="Finland",city="s",town="n",pageNumber=2 })
http:/myList/Finland/s/n/2
ProductList(string country, string city, string town, int? pageNumber)
{
city== "s" ? city = null;
town == "n" ? town= null;
process...
}
to be http: /myList/Finland/2 /myList/Finland/Helsinki/3 /myList/Finland/town/7
Upvotes: 0
Views: 393
Reputation: 1039328
Only the last parameter in your route definition can be optional.
Upvotes: 0
Reputation: 38488
You cannot skip the parameters in that route. You just can't call http://mylist/2 and expect pageNumber to take value 2. Value in first segment is assigned to the first variable in the route. So 2 is assigned to city variable. You have to make sure all parameters before pageNumber gets a non-null value.
Upvotes: 0