Copied to clipboard

Flag this post as spam?

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


  • Adnaan Bhamla 2 posts 72 karma points
    Nov 02, 2019 @ 12:08
    Adnaan Bhamla
    0

    Migrating controller code to v8 - code does not seem to be working as expecting

    I'm currently in the process of migrating a project from Umbraco v7 to v8.

    I'm fairly new to C# so please forgive me if I've missed something very simple!

    I've made an attempt to migrate the code - specifically this var from Umbraco v7:

    var configNodeId = CurrentPage.GetPropertyValue<int?>("configurationNode", true); 
    

    ...replacing the recursive functionality with new fallback option (change below).

    There are no console errors on build throughout my solution but I believe this migrated code isn't functioning how it was in v7.

    Any thoughts or help would be much appreciated!

    namespace PNGBaseUmbracoWebsite.Controllers 
    {
    
    public partial class BaseSurfaceController : SurfaceController
    {
        public new IPublishedContent CurrentPage
        {
            get { return base.CurrentPage; }
        }
    
        public IPublishedContent ConfigNode
        {
            get
            {
                // Umbraco 7
                // var configNodeId = CurrentPage.GetPropertyValue<int?>("configurationNode", true); 
    
                // Umbraco 8
                var configNodeId = CurrentPage.Value<int?>("configurationNode", fallback: Fallback.To(Fallback.Ancestors, Fallback.DefaultValue), defaultValue: null);
    
                if (configNodeId != null)
                {
                    configNode = Umbraco.Content(configNodeId);
                }
            }
        }
    }
    
  • Adnaan Bhamla 2 posts 72 karma points
    Nov 02, 2019 @ 13:00
    Adnaan Bhamla
    0

    Here is the difference I found in the Console while debugging

    Umbraco 7 Umbraco 7 Console Umbraco 8 Umbraco 8 Console Does this explain why I may be having differences in values (displaying as null in v8) further down the pipeline?

  • 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