Copied to clipboard

Flag this post as spam?

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


  • Paul de Quant 403 posts 1520 karma points
    Jun 28, 2021 @ 09:06
    Paul de Quant
    0

    Block List Editor - Getting parent Id

    Hello,

    Is it possible to get an id of the parent block list editor from one of it's child parts.

    I need to get a unique id from the block list editor control and reference it in a child content part.

    Is this possible?

    Thanks

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Jun 28, 2021 @ 09:34
    Søren Gregersen
    1

    Hi Paul,

    The BlockListModel only contains a list of BlockListItem, wich has a ContentUdi and a SettingsUdi.

    If you need to reference your BlockListModel, you could send it to your blocks. There is a few ways of doing that.

    New Model:

    public class ModelAndItem {
        public BlockListModel Model { get; set; }
        public BlockListItem Item { get; set; }
    }
    

    And in the BlockList/Default.cshtml:

    @Html.Partial("BlockList/Components/" + data.ContentType.Alias, new ModelAndItem{ Model = Model, Item = block })
    

    Then in your block, you reference it:

      var blockListModel = Model.Model;
      var block = Model.Item; 
    

    Add to ViewData:

    @Html.Partial("BlockList/Components/" + data.ContentType.Alias, block, new ViewDataDictionary{ { "BlockListModel", Model }})        
    

    Then in your block, you reference it:

      var blockListModel = this.ViewData["BlockListModel"] as BlockListModel;
    
  • Paul de Quant 403 posts 1520 karma points
    Jun 28, 2021 @ 10:00
    Paul de Quant
    0

    Hi Søren,

    thanks for the reply, would these options work for Html.GetBlockListHtml (which is what we're using at the moment)

    Thanks

  • Amir Khan 1282 posts 2739 karma points
    Jan 05, 2022 @ 18:54
    Amir Khan
    0

    Were you able to solve for this? Im using the same and am trying to get the value of a property from the containing page with no luck.

    I'm actually getting an error when trying to create that class as well:

    Cannot bind source type ModelAndItem to model type Umbraco.Core.Models.Blocks.BlockListItem.
    
Please Sign in or register to post replies

Write your reply to:

Draft