Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nathan Reece 62 posts 376 karma points
    Aug 04, 2020 @ 06:23
    Nathan Reece
    0

    Rendering Links to View in Umbraco 8

    Can anyone help me?

    I am trying to add a link to my site using Nested Content and the Url Picker, I have everything displayed using razor code but my links are showing as " Umbraco.Web.Models.Link "

    Here is a sample of my code ( its supposed to just be a test link navigating home )

        </div>
        <div class="col-md-4">
            @if (nestedContent.Link != null)
            {
                <a href="/">@nestedContent.Link</a>
            }
        </div> 
    

    Is there something Im missing or doing wrong?

  • David Armitage 508 posts 2078 karma points
    Aug 04, 2020 @ 06:36
    David Armitage
    100

    Hi Nathan,

    It looks like you are using models builder so this should work..

    @if (nestedContent.Link != null)
            {
                <a href="@nestedContent.Link.Url" target="@nestedContent.Link.Target">@nestedContent.Link.Name</a>
            }
    

    If you are not using models builder then something I think I think should work.

     var link = Model.Value<Umbraco.Web.Models.Link>("linkAliasHere");
                        if(link != null)
                        {
                            <a href="@link.Url" target="@link.Target">@link.Name</a>
                        }
    

    Regards

    David

  • Nathan Reece 62 posts 376 karma points
    Aug 04, 2020 @ 07:20
    Nathan Reece
    0

    Thanks Dave, Great help its working perfectly now!

Please Sign in or register to post replies

Write your reply to:

Draft