Copied to clipboard

Flag this post as spam?

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


  • Manish Manandhar 5 posts 74 karma points
    Oct 27, 2021 @ 06:26
    Manish Manandhar
    0

    Previously created content of BlockListItem returns null settings

    For BlockListItem, previoulsy created content returns the data of the content but for the settings, it returns null.

    If we create new content then it returns proper content and settings data.

    It is not feasible to replace every older content with new ones.

    Any solution for this issue?

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<Umbraco.Core.Models.Blocks.BlockListItem>
    
        @{
            TextBoxSideImage content = (TextBoxSideImage)Model.Content;  //returns the content
            BaseTextBoxSideImageSettings setting = (BaseTextBoxSideImageSettings)Model.Settings; //returns null
         }
    
  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Oct 27, 2021 @ 06:57
    Søren Gregersen
    1

    Hi Manish,

    The content is currently stored as json, and there is nothing that updates that json when you edit the definition.

    I think you have to make changes to the current data, saving new settings, if you really need it. In any case, you should always write code that can handle something being null.

    Often we read settings like:

    var settingValue = (Model.Settings as BlockTypeSettings)?.SomeSettingValue ?? "default value";
    if(settingValue != null){
       // use setting...
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft