Copied to clipboard

Flag this post as spam?

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


  • BEWD 89 posts 301 karma points
    Mar 13, 2016 @ 15:30
    BEWD
    0

    Hyperlink in Partial View not linking to the page

    Hi All

    I am hoping someone can help me?

    I have a "Menus" page with a MultiNode Tree Picker on it which selects items from a particular section.

    I have created a partial view called "listMenuItems" which includes several fields such as an image, text and a link which is specified via a content picker. However, I cant for the life of me get the hyperlink to work (everything else works fine). The link Alias is "linkTo"

    My Partial view is :

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{ var selection = CurrentPage.insertMenuItems.Split(','); }
    
    @foreach (var id in selection)
    {
        var item = Umbraco.Content(id);
            <div class="col-sm-4">
               <div class="service wow fadeInDown">
                  <div class="service-icon"><i class="fa [email protected]"></i></div>
                     <h3>@item.Name</h3>
                     <p>@item.MenuItemText</p>
                     <a class="big-link-1" href="@Umbraco.Content("LinkTo").Url">View Menu</a>
               </div>
             </div>
    
    }
    

    The line that doesn't work is:

    <a class="big-link-1" href="@Umbraco.Content("LinkTo").Url">View Menu</a>
    

    I am sure I am doing something obvious here but I have been looking at it so long and tried everything I can think of. Any Ideas would be greatfully revieved

    Ben

  • Sebastiaan Janssen 5045 posts 15476 karma points MVP admin hq
    Mar 13, 2016 @ 18:25
    Sebastiaan Janssen
    100

    I'm assuming the link is a property with the alias LinkTo on each item in your selection?

    After var item = Umbraco.Content(id); you probably want:

    var linkId = item.GetPropertyValue("LinkTo");
    

    The your link should look like:

    <a class="big-link-1" href="@Umbraco.Content(linkId).Url">View Menu</a>
    

    You will also want to make sure that there is actually a link, so something like:

    var item = Umbraco.Content(id);
    var link = string.Empty;
    if (item.HasValue("LinkTo"))
    {
        var linkId = item.GetPropertyValue("LinkTo");
        var linkItem = Umbraco.Content(linkId);
        if (linkItem != null)
        {
            link = linkItem.Url;
        }
    }
    

    And then your link can look like:

    @if (string.IsNullOrWhiteSpace(link) == false)
    {
        <a class="big-link-1" href="@link">View Menu</a>
    }
    
  • BEWD 89 posts 301 karma points
    Mar 13, 2016 @ 18:48
    BEWD
    0

    Thank you so much Sebastiaan, That has worked perfectly.

    I very much appreciate it.

Please Sign in or register to post replies

Write your reply to:

Draft