Block without properties



I have one question regarding blocks: is it true that you have to have at least one property for block, or you'll get null exception?

I was tring to find simmilar topic on forum but I coudln't find any, so please forgive me if I'll duplicate topics :)


Thanks in advance for answering!

Jun 17, 2013 11:35

I have a couple blocks in our system that are purely javascript based and used for ad tags, these have no properties at all on them and work just fine!  

Are you creating blocks without properties and finding that you receive a null exception?

Jun 18, 2013 16:35

I'm not sure as well, but some article about related bug comes to my mind. Anyway - if you create block with any property nad  drop iand drop it on ContentArea - hat's fine. But if you define this block as property of other content (page for instance) - then I received some weired exceptions during rendering phase. By adding any dummy property to the block seemed to solve the issue.

Jun 18, 2013 23:37

The scenario you describe sounds correct.  Using a blockdata class as a "property group" on a pagedata class basically is creating a grouping of the properties within the blockdata for you on the page.  I'm assuming since there's no properties, and your using it as a "local block" (that is, as a property group on a pagedata class) - the system can't find anything to output and therefor throws the exceptions you see.

Jun 18, 2013 23:50

I 'partially' understand why its not possible to put block without any property on the page (not as shared block dragged on content are). There is no need in using block as a property, cause you don't put any data and you can just use 




When you need to use block from other reasons (shared block in different places), you can Html.RenderPartial("Blocks/PathToBlockView"); without passing a model (which is not needed btw).

Jun 21, 2013 2:00

Krzysztof, what I don't really like about using Html helper for that reason is fact that you loose strongly typed approach. In my opinion this:

@Html.PropertyFor(x => x.YourBlockProperty);


Is a bit better than:




Jun 23, 2013 16:28

@Valdis, I agree that we should use strongly typed approaches when possible (at least in strongly typed languages). In this case (block without any properties) PropertyFor:

@Html.PropertyFor(x => x.YourBlockProperty);


will throw very unfriendly NullReferenceException. They treat it wired in EPi ;) I didn't look into source, but there are the symptomps.

Jun 26, 2013 9:48

Thanks guys for help!

It turned out that, as Mike wrote, it shouldn't be a block but just partial view.

Jul 01, 2013 14:24
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.