Copied to clipboard

Flag this post as spam?

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


  • Dave Arkless 2 posts 72 karma points
    Sep 14, 2021 @ 02:49
    Dave Arkless
    0

    Media Picker always returning null

    Hi,

    I have searched and searched and whilst I have found others with a similar issue, I haven't found an answer which has resolved my issue. If anyone can assist I would be very grateful as this is driving me mad.

    I have added a media picker "field" to a document type page which is used as a category of products, under which are other document types for the products themselves.

    I am trying to add the option to select a banner which will act as the title of the page. I simply cannot get it to return anything other than null.

    Here is my template code:

    @inherits Amplify.Web.Custom.ViewPages.AmplifyViewPage<CatTowelRails>
    @using Amplify.Web.Custom.Extensions
    @{
        Layout = "master.cshtml";
        var products = Model.Children.Select(x => new ProductTowelRail(x));
    }
    
    
        @{
            var image = Model.Value<IPublishedContent>("TitleImage");
    
            if(image != null)
            {
                <p>@image.Url</p>
            }
            else
            {
                @Html.Partial($"~/Views/Partials/PageHeader.cshtml", Model);
            }
        }
    

    Here is an image of the document type set up:

    enter image description here

    Here is the image of the content having been set

    enter image description here

    All suggestions welcome, because I am stuck!!

    Thanks in advance

    Dave

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 9x admin c-trib
    Sep 14, 2021 @ 12:43
    Alex Skrypnyk
    0

    Hi Dave

    Please, check media picker property alias, it's casesensitive. This code should work:

    var image = Model.Value<IPublishedContent>("titleImage");
    

    Thanks,

    Alex

  • Dave Arkless 2 posts 72 karma points
    Sep 15, 2021 @ 01:17
    Dave Arkless
    0

    Hi Alex,

    Thanks for your reply. I have tried with the code as you suggested and matching the alias exactly, however I get the same result. Null being returned.

    @{
        var image = Model.Value<IPublishedContent>("titleImage");
    
        if(image != null)
        {
            <p>@image.Url</p>
        }
        else
        {
            <p>Image is null</p>
            //@Html.Partial($"~/Views/Partials/PageHeader.cshtml", Model);
        }
    }
    

    enter image description here

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies