【发布时间】:2014-05-16 13:19:53
【问题描述】:
我正在使用 umbraco 7 ASP.NET C# MVC 4。
我正在尝试使用新的 umbraco,到目前为止一切正常,但我需要获取我设置的一个页面的属性。
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
var homePage = CurrentPage.AncestorsOrSelf(1).First();
var menuItems = homePage.Children.Where("isMenu == true");
}
<!-- Nav -->
<div class="row">
<div class="col-md-12 top-menu-container">
<ul>
@* If the Url of the current page is "/" then we want to add the class "current_page_item" *@
@* Otherwise, we set the class to null, that way it will not even be added to the <li> element *@
<li>
<div onclick="location.href='/';" class="col-md-2 metro-container" style="background-color:#@Model.Content.GetPropertyValue("navigationColor")" >
<img class="menu-img" src="../../media/1001/home.png" alt="" />
Home
</div>
</li>
@foreach (var item in menuItems)
{
@* If the Id of the item is the same as the Id of the current page then we want to add the class "current_page_item" *@
@* Otherwise, we set the class to null, that way it will not even be added to the <li> element *@
<li>
<div onclick="location.href='@item.Url';" class="col-md-2 metro-container" style="background-color:#@item.Content.GetPropertyValue("navigationColor")" >
<img class="menu-img" src="../../media/1001/home.png" alt="" />
@item.Name
</div>
</li>
}
</ul>
</div>
</div>
所以循环外的第一个“li”我只需获取模型内容 Getproperty 方法,这肯定足以让我得到我告诉它的任何属性。
尽管我的循环通过了当前页面子项,但我似乎无法获得特定属性。
更糟糕的是智能感知不能作为它的所有运行时工作。
有问题的行是
<div onclick="location.href='@item.Url';" class="col-md-2 metro-container" style="background-color:#@item.Content.GetPropertyValue("navigationColor")" >
我需要从 navigationColor 控件中获取页面上设置的颜色。
我在这里做错了什么?
【问题讨论】:
标签: c# asp.net-mvc-4 umbraco7