My problem is that I give to my action 3 parameters (category, city, page) and some of them could be null because I need to make 3 filterings:
- one by category
(category != null && city == null) - one by city
(category == null && city != null) - one by both of them
(category != null && city != null)
My problem is on routing.
When (category != null && city == null) it doesn’t work. It gives to category parameter from my action null value, and my city parameter receives the category’s value.
My Global.asax:
routes.MapRoute(
"ListByCity",
"Advertisers/{city}/{page}",
new { controller = "Advertisers", action = "List" }
);
routes.MapRoute(
"ListByCategory",
"Advertisers/{category}/{page}",
new { controller = "Advertisers", action = "List" }
);
routes.MapRoute(
"List",
"Advertisers/{category}/{city}/{page}",
new { controller = "Advertisers", action = "List" }
);
Please help me.
think the problem in the opposite way. If you have the URL http://YourServer/Advertisers/Text How would you know if that text is a category or a city?
You can resolve the matching problem with a regular expression but both cities and categories are strings so you have no way of telling the routing system which one to match.
You will have to differenciate them. Maybe creating a route that matches /Advertisers/Categories/{category} and other that matches /Advertisers/Cities/{city}.