Getting parent content area in block

I have a problem getting the content area of the parent page/ block in a block in view mode (in edit mode everything works fine). The main issue I'm trying to solve is to get a blocks position on a page based on it's index.

In my block controller:

public override ActionResult Index(PromotionBlock currentBlock)
            var parentContentArea = ControllerContext?.ParentActionViewContext?.ViewData?.Model as ContentArea;
            currentBlock.Position = _blockUtilities.GetBlockPositionInContentArea(parentContentArea, currentBlock);

            var model = new PromotionBlockViewModel(currentBlock);
            return PartialView(model);

In BlockUtilities

        public string GetBlockPositionInContentArea(ContentArea contentArea, BlockDataBase block)
            var blockContent = (IContent) block;
            return contentArea != null ? contentArea.FilteredItems?.ToList().FindIndex(o => o.ContentGuid == blockContent.ContentGuid).ToString() : string.Empty;

The main issue is that parantContentArea is null, when controller runs in view mode while have correct value in editor mode. When I debug ControllerContext?.ParentActionViewContext?.ViewData?.Model have the correct value, but it looks like the casting is not working. 

Any suggestions of why the casting is not working, or an other way of getting the contentArea ?

#182249 Sep 13, 2017 13:25