Try our conversational search powered by Generative AI!

Get Block data on view

Vote:
 

Hi,

I'm using EPiServer 7.5 MVC. I have a view for my page with a content area. I need to get the datas of block(which comes inside content area) on my page(view). Is it possible?

#82438
Mar 12, 2014 11:52
Vote:
 

Try this:

@{
    var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
    if (page != null && page.ContentArea != null && page.ContentArea.Items.Any())
    {
        foreach (var contentItem in page.ContentArea.Items)
        {
            var item = contentLoader.Get<YOUR_CONTENT_TYPE>(contentItem.ContentLink);          
            // output necessary properties from content instance
        }
    }
}

    

#82458
Mar 12, 2014 21:04
* 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.