Copied to clipboard

Flag this post as spam?

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


  • Colin Wiseman 52 posts 194 karma points
    Sep 11, 2024 @ 09:39
    Colin Wiseman
    0

    UmbracoRedirect is null

    Hey,

    I have added umbracoRedirect property to my document type, setting it to a Content Picker, and as expected it redirects the page when you try to land on it. Good stuff :D

    But I have a content block that renders out a list of pages and would like to use the umbracoRedirect value to render the Url of where Umbraco would redirect the user to if they went direct to the page in question i.e.

    var url = department.Url();
    if(department.UmbracoRedirect != null)
    {
        url = department.UmbracoRedirect.Url();
    }
    

    but unfortunately UmbracoRedirect is null.

    Now... I can get the UmbracoRedirect value thusly:

    var umbracoRedirect = department.Value<Udi>("umbracoRedirect");
    var url = department.Url();
    if (umbracoRedirect != null)
    {
        var redirect = UmbracoContext.Content.GetById(umbracoRedirect);
        if(redirect != null)
        {
            url = redirect.Url();
        }
    }
    

    But that's an ugly addition for me to add to where ever I want to do this (which I could wrap up in an extension method...) but surely this would be nicer as part of the object generation and not me making another call to the cache.

    Is there something I am missing in a setting somewhere for ModelsBuilder?

Please Sign in or register to post replies

Write your reply to:

Draft