Copied to clipboard

Flag this post as spam?

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


  • Nick 95 posts 492 karma points
    Jun 15, 2023 @ 15:53
    Nick
    0

    Rendering Single Url Picker contents error

    Hi,

    Wonderd if somebody could help me, I'm trying to render a Single Url Picker datatype with an alias of infoLink, within a block list element with an alias of infoBannerLink within my Umbraco 11 project, the code is below but I'm receiving the below error is image, I'm a little confused of where I am going wrong, any help would be much appreciated as always :-)

    enter image description here

    @inherits UmbracoViewPage<Umbraco.Cms.Core.Models.Blocks.BlockListItem>
    @using ContentModels = Umbraco.Cms.Web.Common.PublishedModels;
    @using Umbraco.Cms.Web.Common.PublishedModels;
    @using Umbraco.Cms.Core.Models
    
    @{
        var content = (ContentModels.InfoBannerLink)Model.Content;
        var image = content.InfoImage;
        var link = Model.Value<Link>("infoLink");
    }
    <!-- HERO CTA Start -->
    <div class="section subscribe-section">
        <div class="container">
            <div class="info-banner-wrap">
                <div class="section-one">
                    <div class="content image" style="background-image: url(@(image!=null?image.Url():""))">
    
                    </div>
                </div>
                <div class="section-two">
                    <div class="content text">
                        <h2 class="title">@Html.Raw(content.InfoTitle)</h2>
                        <p>@Html.Raw(content.InfoContent)</p>
                            if (link != null)
                            {
                                <a href="@link.Url" target="@link.Target">@link.Name</a>
                            }
                    </div>
                </div>
            </div>
        </div>
    </div>
    
  • Tor Langlo 191 posts 554 karma points
    Jun 15, 2023 @ 20:24
    Tor Langlo
    100

    I think you just have to add Content, so change to:

    var link = Model.Content.Value<Link>("infoLink");
    

    But maybe

    var link = content.InfoLink
    

    works too?

  • Derek 17 posts 71 karma points
    Jun 16, 2023 @ 15:35
    Derek
    0

    Hi Nick,

    No need for the Model.Value<> as you've already cast the Model's content to the content var so as Tor said:

    var link = content.InfoLink
    

    should be fine.

Please Sign in or register to post replies

Write your reply to:

Draft