这是我的主页面布局页面。我正在生成动态菜单,但单击下拉列表不会显示任何项目。我做错了什么?
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.Master>
@using ContentModels = Umbraco.Web.PublishedContentModels;
@{
Layout = null;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>@Umbraco.Field("siteTitle")</title>
<meta name="description" content="@Umbraco.Field("metaDescription", recursive: true)">
<meta name="keyword" content="@Umbraco.Field("metaKeywords", recursive: true)">
<link href="~/Content/bootstrap.css" rel="stylesheet" />
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
</head>
<body>
这是导航部分的开头。
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
@{ IPublishedContent root = Model.Content.AncestorOrSelf(1); }
<ul class="nav navbar-nav">
<li class="@((Model.Content.Name == root.Name) ? "active" : null)">
<a href="/">@root.Name</a></li>
</li>
@foreach (IPublishedContent menuItem in root.Children.Where(x => x.IsVisible())) {
<li class="@((menuItem.Name == Model.Content.Name) ? "active" : null)">
<a href="@menuItem.Url">@menuItem.Name</a>
</li>
}
这是代码开始无效的地方。
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href='@Model.Content.AncestorOrSelf(1).Children.Where(x => x.DocumentTypeAlias == "projectsMain")'>Our Proj<span class="caret"></span></a>
<ul class="dropdown-menu">
@{
IQueryable projectsDropdown =
Model.Content.AncestorOrSelf(1)
.Children
.Where(x => x.DocumentTypeAlias == "projectsMain")
.First()
.Children
.Where("Visible")
.OrderBy("Name");
}
@foreach(IPublishedContent project in projectsDropdown){
var prevalue = project.GetPropertyValue<int>("projectStatus");
if(Umbraco.GetPreValueAsString(prevalue) == "Completed"){
<li><a href="@project.Url">@project.Name</a></li>
}
}
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
@RenderBody();
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="~/Scripts/bootstrap.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
<script src="~/Scripts/jquery-2.2.0.min.js"></script>
</body>
</html>
答案 0 :(得分:1)
您是否尝试过调试方式?您是否检查了生成的HTML源代码以查看下拉菜单中是否有实际的项目?
您使用的是哪种Umbraco版本?看起来像7.x - 所以有更简单的方法来做你做的一些事情。像@ CurrentPage.Site()一样获取根节点。
你包括bootstrap.js和bootstrap.min.js,这可能搞砸了,还包括看起来像两个版本的jQuery?
此外,您在bootstrap.js之后包含(jquery-2.2.0.js)jQuery,这可能也会导致问题。