Copied to clipboard

Flag this post as spam?

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


  • David 27 posts 127 karma points
    Jun 24, 2019 @ 10:36
    David
    0

    How to get the title of a page from a content ID using a grid editor partial view?

    Hi all,

    I've created a grid editor partial view which will display an image and a link of the users choice, however I can only seem to get the content ID for the link the user selects and am struggling to render the text of the link instead of the ID.

    Here's my code:

    @inherits UmbracoViewPage<Lecoati.LeBlender.Extension.Models.LeBlenderModel>
    @using RJP.MultiUrlPicker.Models;
    @using Umbraco.Web.Templates
    
    @if (Model.Items.Any())
    {
    var item = Model.Items.ElementAt(0);
    var imageList = item.GetValue<string>("circularResponsiveImage");
    var borderColour = item.GetValue("approvedColour");
    var link = item.GetValue("link");
    
    
    if (!string.IsNullOrWhiteSpace(imageList))
    {
        var imgList = imageList.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
        var imgListCollection = Umbraco.TypedMedia(imgList);
    
    
        if (imgListCollection != null)
        {
            foreach (var img in imgListCollection)
            {
                <img style="@(!string.IsNullOrWhiteSpace(borderColour) ? "border: 16px solid #" + borderColour : "" ); padding: 0; height: 260px; width: 260px;" src="@img.Url" alt="@img.GetPropertyValue("altText")" class="img-responsive img-circle" />
                @Umbraco.RenderMacro("FullPagePath")
                <ul class = "nav">
                    <li class ="more">
                        <p>@link</p>
                    </li>
                </ul>
            }
        }
    }
    
    
    }
    

    I've tried a number of different methods like GetPropertyValue, GetPropertyValue

    Any help would be really appreciated :)

    Thanks,

    David

  • Marc Goodson 2157 posts 14431 karma points MVP 9x c-trib
    Jun 24, 2019 @ 11:36
    Marc Goodson
    100

    Hi David

    Is it this line

    var link = item.GetValue("link");
    

    is the link a RJP.MultiUrlPicker?

    how about

      linkUrls = item.HasProperty("link") ? titleAndButton.GetValue<MultiUrls>("link) : default(MultiUrls);
    var link = linkUrls != null ? linkUrls.FirstOrDefault() : default(Link);
    

    then you can access

    @link.Url @link.Target @link.Name

    It depends a little on the version of the RJP you are using where MultiUrls has been replaced by an IEnumerable but same theory should work...

    If I'm wrong and the link is a content picker then

    pickedLink = Umbraco.TypedContent(item.GetValue("link"));
    

    should get you details of the picked item.

    regards

    marc

  • David 27 posts 127 karma points
    Jun 24, 2019 @ 13:51
    David
    0

    Hi Marc,

    Thanks for taking the time to reply to me, it was a content picker and this solved the problem for me! I'll also remember to reference this when using a multi url picker.

    Thanks again, I really appreciate it.

    David

Please Sign in or register to post replies

Write your reply to:

Draft