Block without properties

Vote:
 

Hi!

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!

#72422
Jun 17, 2013 11:35
Vote:
 

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?

#72485
Jun 18, 2013 16:35
Vote:
 

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.

#72498
Jun 18, 2013 23:37
Vote:
 

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.

#72499
Jun 18, 2013 23:50
Vote:
 

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 

  

Html.RenderPartial("PathToTheView");

    

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).

#72572
Jun 21, 2013 2:00
Vote:
 

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:

Html.RenderPartial("PathToTheView");

    

 

#72588
Jun 23, 2013 16:28
Vote:
 

@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.

#72667
Jun 26, 2013 9:48
Vote:
 

Thanks guys for help!

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

#72833
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.