我正在使用ASP.Net 4.5 w / MVC 5.2.2.0,并尝试将面包屑样式导航添加到具有五个导航深度级别的应用程序中。我进入了第四级,并在测试概念验证页面时发现了一个奇怪的问题。除了最低级别以外的所有工作都很好。
以下是路由规则:
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
}
);
}
}
该模型如下所示:
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; }
...
}
以下是我的观点代码:
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>
此代码为/ Controller / Action / X / Y / Z / 4呈现以下HTML:
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>
为什么第一个级别/Controller/Action/X
不会像其他级别一样生成?