Try our conversational search powered by Generative AI!

Get block from ContentArea

Vote:
 

Hi,

I'm trying to get a hold of a property belonging to the block, of type MyBlock, that I have in a ContentArea.

I have the following code:

private string ShowSavingsAdvice(IList list)
        {
            var contentLoader = ServiceLocator.Current.GetInstance();
            foreach (var item in list)
            {
                var block = contentLoader.Get(item.ContentLink);
                
            }

            return "";
        }

The variable block is now of the type MyBlockProxy. How do I get it to be of type MyBlock so that I can get a hold of its properties?

#147054
Apr 05, 2016 12:42
Vote:
 

var block = contentLoader.Get<MyBlock>(item.ContentLink)

or

var block = contentLoader.Get<BlockData>(item.ContentLink) as MyBlock

#147055
Apr 05, 2016 12:44
Vote:
 

Yes it works did forget the using XD!

#147056
Edited, Apr 05, 2016 13:15
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.