嗨,我想在我的 li 中添加一个“活动”类,如果它是活动的,或者我在它下面的页面上。我有以下代码
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
Layout = null;
}
<nav class="topNav">
<ul>
@foreach (var item in Model.Content.AncestorOrSelf(1).Children.Where(x => x.IsVisible() && x.IsDocumentType("Subfrontpage") || x.IsDocumentType("Procesguide")))
{
<li>
<a href="@item.Url">@item.Name</a>
</li>
}
</ul>
</nav>
我想我可以用这个做点什么,但它给出了一个错误
var isSelected = Model.Path.Contains(item.Id.ToString()) ? "active" : "";
<li class="@Html.Raw(isSelected)">
<a href="@item.Url">@item.Name</a>
</li>
这是我得到的错误。第 10 行。
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1061: 'Umbraco.Web.Models.RenderModel' does not contain a definition for 'Path' and no extension method 'Path' accepting a first argument of type 'Umbraco.Web.Models.RenderModel' could be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 8: @foreach (var item in Model.Content.AncestorOrSelf(1).Children.Where(x => x.IsVisible() && x.IsDocumentType("Subfrontpage") || x.IsDocumentType("Procesguide")))
Line 9: {
Line 10: var isSelected = Model.Path.Contains(item.Id.ToString()) ? "active" : "";
Line 11:
Line 12: <li class="@Html.Raw(isSelected)">
我现在已经尝试过了,但没有 lunk
<ul>
<li>
<a href="@home.Url">@home.Name</a>
</li>
@foreach (var item in Model.Content.AncestorOrSelf(1).Children.Where(x => x.IsVisible() && x.IsDocumentType("Subfrontpage") || x.IsDocumentType("Procesguide")))
{
var isSelected = item.IsDescendant(Model,"active", "");
<li class="@Html.Raw(isSelected)">
<a href="@item.Url">@item.Name</a>
</li>
}
</ul>