Search code examples
asp.net-mvcrazorumbracoasp.net-mvc-partialview

Umbraco - Content Picker value for <a> tags


I am trying to use a content picker's value for a href in a partial view but I am struggling to get the format right...

I have been using

@(node.GetPropertyValue("propertyAlias"))

but when I use this in an it just displays the ID of the node. How can I get it to give me the URL of the node?

<a href="@(node.GetPropertyValue("link"))">Link</a>



    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        var items = CurrentPage.FirstChild("folder").Children("item").Where("Visible");

    }

    <div class="row tile-row">
        @foreach(var node in items)
        {
            <div class="col-md-3">
                <div class="tile">
                    <h3>@(node.GetPropertyValue("itemTitle"))</h3>
                    @(node.GetPropertyValue("itemBodyText"))<br/>
                    @(node.getPropertyValue("itemButtonLink"))

<a class="btn btn-more" href="@(node.GetPropertyValue("itemeButtonLink"))">
   @(node.GetPropertyValue("itemButtonText"))
</a>            


                </div>  
            </div>
        }
    </div><!--/.row-->

Solution

  • I managed to get the Url of the item using the code below

    <p>@Umbraco.NiceUrl(node.GetPropertyValue<int>("itemButtonLink"))</p>
    
    <a href="@Umbraco.NiceUrl(node.GetPropertyValue<int>("itemButtonLink"))">
        @(node.GetPropertyValue("itemButtonText")
    </a>
    

    I hope this helps anyone else out who has been struggling with the same issue - Credit owed to - https://gist.github.com/tobbbe/7784542