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
    14 days ago
    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 6048 posts 23038 karma points MVP 5x admin c-trib
    1 week ago
    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
    1 week ago
    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

Please Sign in or register to post replies

Write your reply to:

Draft