Copied to clipboard

Flag this post as spam?

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


  • Owain Williams 479 posts 1410 karma points MVP 6x c-trib
    Aug 07, 2018 @ 19:07
    Owain Williams
    0

    Hi everyone

    I'm having strange issue with trying to get the URL from a RJP.MultiUrlPicker.

    My code looks like this:

    @inherits UmbracoViewPage<ContentModels.CallToActionListing>
    @using ContentModels = Umbraco.Web.PublishedContentModels;
    @{
        Layout = null;
    }
    
    
    @Model.SectionHeader
    
    @{
        if (Model.HasValue("CallToActions"))
        {
    
    
    
            var cta = Model.CallToActions.Select(c => new CallToAction(c)).ToList();
    
    
            foreach (var callToAction in cta)
            {
    
                if (callToAction.CallToActionIcon != null)
                {
                    <div class="card">
                        <div class="cardInner">
                            @{
                                var typedMediaPickerSingle = callToAction.CallToActionIcon;
                                if (typedMediaPickerSingle != null)
                                {
                                    <div class="cardImg">
                                        <img src="@typedMediaPickerSingle.Url" alt="@typedMediaPickerSingle.GetPropertyValue("alt")" />
                                    </div>
                                }
                            }
                            <div class="cardContent">
                                @if (callToAction.CallToActionText != null)
                                {
                                    <p>@callToAction.CallToActionText</p>
    
                                }
                                @if (callToAction.CallToActionText != null)
                                {
                                    <a class="btn btnIcon" href="@callToAction.CallToActionLink.Url">@callToAction.CallToActionLinkText</a>
                                }
                            </div>
                        </div>
                    </div>
                }
                else
                {
                    <p>
    
    
    
                        @callToAction.GetPropertyValue("ColourForCallToAction")<br />
                        @callToAction.GetPropertyValue("CallToActionText")<br />
    
                        @if (callToAction.GetPropertyValue("ButtonText") != null)
                        {
    
                        }
                        @callToAction.GetPropertyValue("Link")<br />
    
    
    
                    </p>
    
                }
    
    
    
            }
    
    
    
        }
    }
    

    I'm using Models Builder and Nested Content. enter image description here

    The if statement if (callToAction.CallToActionIcon != null) { works perfectly, it gives me the image, the text and the link and so I expected to be able to get the else to work just as easy. I was wrong.

    enter image description here

    As you can see, the first statement works, I have the image, the text and the lin, but the component above that just outputs RJP.MultiUrlPicker.Models.Link.

    I've tried a number of different thinks and I either get a # as the link, an error, or nothing at all!

    I really hope someone can help. I'm open to suggestions on how to make the code better too.

    Cheers.

    Owain

  • Nik 1591 posts 7148 karma points MVP 6x c-trib
    Aug 07, 2018 @ 19:12
    Nik
    103

    Hey Owain :-)

    Try replacing this:

     @callToAction.GetPropertyValue("Link")
    

    with:

     @{
         var link = callToAction.GetPropertyValue<RJP.MultiUrlPicker.Models.Link>("Link");
          <a href="@link.Url">@link.Name</a>
     }
    

    A property value converter is converting your value to the model RJP.MultiUrlPicker.Models.Link and by just calling @callToAction.GetPropertyValue("Link") razor is calling the .ToString() method on it. So that is why you are seeing the class name :-)

    edit don't forget null checks :-)

    Cheers

    Nik

  • Owain Williams 479 posts 1410 karma points MVP 6x c-trib
    Aug 07, 2018 @ 19:21
    Owain Williams
    1

    Cheers for the speedy reply Nik! Problem solved!

    h5yr

    O.

Please Sign in or register to post replies

Write your reply to:

Draft