Just started experimenting with routing. There is such a construction:

routes.MapRoute( "1", "{controller}/{1}", new { controller = "Controller", action = "Action" } ); routes.MapRoute( "2", "{controller}/{2}", new { controller = "Controller", action = "Action" } ); routes.MapRoute( "3", "{controller}/{3}", new { controller = "Controller", action = "Action" } ); routes.MapRoute( "12", "{controller}/{1}/{2}", new { controller = "Controller", action = "Action" } ); routes.MapRoute( "13", "{controller}/{1}/{3}", new { controller = "Controller", action = "Action" } ); routes.MapRoute( "23", "{controller}/{2}/{3}", new { controller = "Controller", action = "Action" } ); routes.MapRoute( "123", "{controller}/{1}/{2}/{3}", new { controller = "Controller", action = "Action" } ); 

The idea is clear: to make it so that deleting a line (or not sending a line) of one or several parameters (including in the middle) does not lead to errors.

When the parameter 3 is a small problem, but it is worth to increase them at least twice, because it requires a much larger code. Of course, this ultimately concerns a predictable number of parameters.

Maybe I do not see a better way to generate correct routing.

PS: If you are interested, then I use such a routing for a flexible filter of an online store: thus the line is deprived of the mention of unnecessary defaults, it looks more accurate and CNC-shnoy.

  • since the order of the parameters is not important in the parameters, it is better to use the querystring instead of the main part of the url - Grundy
  • @Grundy order parameters preferred. And about querystring, I have never come across this concept. Much harder to set up a simple routing? - Denis Kutovskiy
  • on the contrary: querystring is the part coming after ? the parameters that are in action, but not in the route are taken from there - Grundy
  • @Grundy and it’s not difficult for you to write in a separate answer approximately what will the solution of my problem you offer look like? My version suits me, until it comes to a separate schedule / {1} / {2} / {3} / {4}, etc. - Denis Kutovskiy

0