0

In my ASP.NET MVC 4 mobile application, I have a route defined as:

routes.MapRoute(
                name: "GraveNavigation",
                url: "Unites/{development}/{field1}/{field2}/{field3}/{field4}/{field5}", //each development have unique location hierarchy. One may have Section/Block/Path/Lot/Unit, another may only have Block/Lot/Unit.
                defaults: new
                        {
                            controller = "Unit",
                            action = "Index",
                            development= UrlParameter.Optional,
                            field1 = UrlParameter.Optional,
                            field2 = UrlParameter.Optional,
                            field3 = UrlParameter.Optional,
                            field4 = UrlParameter.Optional,
                            field5 = UrlParameter.Optional
                        }
            );

If I use the method in this page, I will always get a null vdp IF I HAVE MORE THAN FOUR(4) OPTIONAL PARAMETERS. Therefore, with "Unites/{development}/{field1}/{field2}/{field3}", it works ok and I get a valid VirtualPathData. Once I have "Unites/{development}/{field1}/{field2}/{field3}/{field4}..." as route URL, RouteTable.Routes.GetVirtualPath always return null.

If I use @Url.RouteUrl utility on a View, I can construct an tag but with the same problem:

var v = oneLevelInTheHierarchy;

<a href='@Url.Action("Index", new { cemetery = v.development, field1 = v.field1, field2 = v.field2, field3 = v.field3, field4 = v.field4 })'>@v.Name</a>

This takes hours to figure out and there are very limited discussion online. Therefore, this makes me wander if asp.net 4 routing supports more than 4 optional parameters?

Or if I use the method incorrectly?

1 Answers1

0

Why not use use a catchall:

  routes.MapRoute(
            name: "GraveNavigation",
            url: "Unites/{development}/{*fields}"
            ...);
Chad Carisch
  • 2,422
  • 3
  • 22
  • 30