I'm using ASP.Net 4.5 w/ MVC 5.2.2.0, and trying to add breadcrumb style navigation to an app that has five levels of navigational depth. I got to the fourth level, and noticed a weird problem during testing a proof of concept page. All but the lowest level work fine.
Here is the routing rule:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "DefaultIds",
url: "{controller}/{action}/{id}/{id2}/{id3}/{id4}/{id5}",
defaults: new { controller = "Home", action = "Index",
id = UrlParameter.Optional,
id2 = UrlParameter.Optional,
id3 = UrlParameter.Optional,
id4 = UrlParameter.Optional,
id5 = UrlParameter.Optional
}
);
}
}
The model looks like this:
public class TestModel : BaseModel
{
public string id { get; set; }
public string id2 { get; set; }
public string id3 { get; set; }
public int? id4 { get; set; }
public int? id5 { get; set; }
...
}
Here is the code for my view:
Action
> <a href="@Url.Action("Action", new { id = Model.id, id2 = null as object, id3 = null as object, id4 = null as object })">@Model.IdName</a>
> <a href="@Url.Action("Action", new { id = Model.id, id2 = Model.id2, id3 = null as object, id4 = null as object })">@Model.Id2Name</a>
> <a href="@Url.Action("Action", new { id = Model.id, id2 = Model.id2, id3 = Model.id3, id4 = null as object })">@Model.Id3Name</a>
> <a href="@Url.Action("Action", new { id = Model.id, id2 = Model.id2, id3 = Model.id3, id4 = Model.id4 })">@Model.Id4Name</a>
This code renders the following HTML for /Controller/Action/X/Y/Z/4:
Action
> <a>X</a>
> <a href="/Controller/Action/X/Y">Y-Name</a>
> <a href="/Controller/Action/X/Y/Z">Z-Name</a>
> <a href="/Controller/Action/X/Y/Z/4">4-Name</a>
Why does the first level, /Controller/Action/X
, not generate like the others?