London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

Unable to cast blocktype to IContent

Vote:
 

I have a block called XFormBlock. The default controller/action is this.

public class XFormBlockController : BlockController<XFormBlock>
    {
        [ChildActionOnly]
        public override ActionResult Index(XFormBlock currentBlock)
        {
}

      }

Now I want to cast the currentBlock to IContent but when doing so I get null. IContent iContent = (currentBlock as IContent);
XFormBlock inherits from BlockData so why can't I do this?

Thanks!

 

 

#77662
Nov 22, 2013 12:05
Vote:
 

Are you using the block as a shared block, or as a property on a page? If it is a property of a page, you cannot convert it to an IContent as it will just be a set of properties.

#77670
Nov 22, 2013 14:01
Vote:
 

I see. It is a property on a page. Thanks!

#77671
Nov 22, 2013 14:02
Vote:
 

The cast will be not null when the block instance is a shared block. When it is a block property instance (for example a block property on a page) then it will be null. It is only shared block instances that implement IContent. See more :http://world.episerver.com/Blogs/Johan-Bjornfot/Dates1/2012/11/Shared-blocks--IContent/

#77672
Nov 22, 2013 14:04
Vote:
 

Per Magne beat me...:-)

#77673
Nov 22, 2013 14:04
Vote:
 

This isn't a competion. Everyone gets "Accepted answer"! (Hi Sweden)

#77674
Nov 22, 2013 14:06
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.