gpt4 book ai didi

c# - MvcSiteMapProvider - 增强的 Bootstrap 下拉菜单

转载 作者:太空宇宙 更新时间:2023-11-03 15:38:38 24 4
gpt4 key购买 nike

我正在尝试构建这样的菜单: image

作为引用,我正在使用这个库 https://github.com/behigh/bootstrap_dropdowns_enhancement

@Html.MvcSiteMap().Menu("BootstrapMenuHelperModel")

@model MenuHelperModel

<nav class="navbar" role="navigation">
<div class="container-fluid menu-container">
<div class="collapse navbar-collapse">
<div class="navbar-header">
<span class="navbar-brand">FAR BACKOFFICE</span>
</div>
<ul class="nav nav-pills">
@foreach (var node in Model.Nodes)
{
if (node.Descendants.Any())
{
<li role="presentation" class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-expanded="false">@node.Title <span class="caret"></span></a>
<ul class="dropdown-menu">
@foreach (var descendant in node.Descendants)
{
if (descendant.Descendants.Any())
{
<li role="presentation" class="dropdown-submenu">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-expanded="false">@descendant.Title</a>
<ul class="dropdown-menu">
@foreach (var descendant2 in descendant.Descendants)
{
<li role="presentation">@Html.ActionLink(descendant2.Title, descendant2.Action, descendant2.Controller)</li>
}
</ul>
</li>
}
else
{
<li role="presentation">@Html.ActionLink(descendant.Title, descendant.Action, descendant.Controller)</li>
}
}
</ul>
</li>
}
else
{
<li role="presentation">@Html.ActionLink(node.Title, node.Action, node.Controller)</li>
}
}
</ul>
</div>
</div>
</nav>

我的 Controller

[MvcSiteMapNode(Title = "Assembleia", ParentKey = "Home", Key = "Assembleia", Clickable = false, Attributes = @"{ ""visibility"": ""SiteMapPathHelper,MenuHelper,!*"" }")]
public class AssembleiaController : Controller { }

[Route("Assembleia/Comunicado")]
[MvcSiteMapNode(Title = "Comunicado", ParentKey = "Assembleia", Key = "AssembleiaComunicado", Clickable = false, Attributes = @"{ ""visibility"": ""SiteMapPathHelper,MenuHelper,!*"" }")]
public class AssembleiaComunicadoController : AssembleiaController
{
[Route("Assembleia/Comunicado/Enviar")]
[MvcSiteMapNode(Title = "Enviar", ParentKey = "AssembleiaComunicado", Key = "AssembleiaComunicadoEnviar", Attributes = @"{ ""visibility"": ""SiteMapPathHelper,MenuHelper,!*"" }")]
public ActionResult Enviar()
{
return View();
}

[HttpGet]
[Route("Assembleia/Comunicado/Consultar")]
[MvcSiteMapNode(Title = "Consultar", ParentKey = "AssembleiaComunicado", Key = "AssembleiaComunicadoConsultar", Attributes = @"{ ""visibility"": ""SiteMapPathHelper,MenuHelper,!*"" }")]
public ActionResult Consultar()
{
return View();
}
}

结果我得到了一个奇怪的和未知的行为 image image

出了什么问题?

也在 GitHub 上询问

最佳答案

node.Descendants 应该是 node.Children

在这里了解后代和子代的区别,CSS Child vs Descendant selectors (不要介意关于 CSS 的帖子,这是一个通用模式)

关于c# - MvcSiteMapProvider - 增强的 Bootstrap 下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30979091/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com