November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
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?
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.
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.
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).
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");
@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.
Thanks guys for help!
It turned out that, as Mike wrote, it shouldn't be a block but just partial view.
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!