umbraco 7: get property value

lemunk picture lemunk · May 16, 2014 · Viewed 13.2k times · Source

I am using umbraco 7 ASP.NET C# MVC 4.

Im trying to use the new umbraco, so far its been ok, but i need to get a property of one of my pages i set up.

@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>

So the first "li" outside the loop i simply get the models content Getproperty method which surely enough gets me any property i tell it too.

However the loop i have although goes through the current pages children, i cant seem to get a specific property.

Makes it worse is intellicense Isn't working as its all runtime.

The line in question is

<div onclick="location.href='@item.Url';"  class="col-md-2 metro-container" style="background-color:#@item.Content.GetPropertyValue("navigationColor")" >

I need to get the color that was set on the page from the navigationColor control.

What am i doing wrong here?

Answer

lemunk picture lemunk · May 16, 2014

Big derp on my side.

The item var in the foreach loop already has property's contained in the item.

all you need to do is

item.NameofYourPropertyAlias

and that should do it.