I have a block called XFormBlock. The default controller/action is this.
public class XFormBlockController : BlockController<XFormBlock>
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?
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.
I see. It is a property on a page. Thanks!
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/
Per Magne beat me...:-)
This isn't a competion. Everyone gets "Accepted answer"! (Hi Sweden)