Copied to clipboard

Flag this post as spam?

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


  • Paul Griffiths 370 posts 1021 karma points
    Sep 25, 2016 @ 08:41
    Paul Griffiths
    1

    Umbraco.TypedContent YSOD when passed an ID of page that has been unpublished

    Hi All,

    In my application i have a MOM property that allows editors to choose another IPublishedContent node (which is a player) for man of teh match. Here is my code

                        @if (fixRes.HasValue("mom"))
                    {
    
                        var mom = Umbraco.TypedContent(fixRes.GetPropertyValue<int>("mom"));
                        <p class="mom">
                            <span>MOM:</span> <a href="@mom.Url">@mom.Name</a>
                        </p>
                    }
    

    However, if a player node that has been selected in a MOM property has been unpublished from the site then it is causing a YSOD. The error seems very similar to this bug that has been raised expect the page has not been deleted. http://issues.umbraco.org/issue/U4-1300#tab=Comments.

    Is there a fix for this, or is there a way that i can check if

    Umbraco.TypedContent(fixRes.GetPropertyValue<int>("mom")
    

    returns null and deal with the exception.

    I dont really want to have to trawl through many pages to delete links each time a player is unpublished from the site.

    Any suggestions

    Paul

  • Alex Skrypnyk 6182 posts 24283 karma points MVP 8x admin c-trib
    Sep 25, 2016 @ 08:50
    Alex Skrypnyk
    1

    Hi Paul,

    IPublishedContent works only if node is publushed, maybe you can try another way for managing nodes, not publish unpublish, maybe try to use some one more picker?

    Thanks

  • Paul Griffiths 370 posts 1021 karma points
    Sep 25, 2016 @ 09:15
    Paul Griffiths
    0

    Hey Alex,

    Thanks foro the response.

    Ha that does make sense considering its called iPublishedContent :). Unless someone can suggest something better I may look at using the relatedLinks datatype, i know that this doesnt YSOD.

    Mnay thanks Paul

  • Alex Skrypnyk 6182 posts 24283 karma points MVP 8x admin c-trib
    Sep 25, 2016 @ 16:36
    Alex Skrypnyk
    0

    Hi Paul,

    Can you share how did you solve your issue?

    So topic is solved.

    Thanks,

    Alex

  • Paul Griffiths 370 posts 1021 karma points
    Sep 25, 2016 @ 18:40
    Paul Griffiths
    0

    Hi Alex,

    As soon as i implement something that resolves this issue i will post my code so that it helps others ;). I havent had time to take a look just yet.

    Thanks

    Paul

  • Kevin Jump 2348 posts 14896 karma points MVP 8x c-trib
    Sep 25, 2016 @ 19:18
    Kevin Jump
    100

    Hi Paul,

    checking the returned value for null should be enough ?

        var mom = Umbraco.TypedContent(fixRes.GetPropertyValue<int>("mom"));
        if (mom != null)
        {
            <p class="mom">
                <span>MOM:</span> <a href="@mom.Url">@mom.Name</a>
            </p>
        }
    
  • 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