November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
If you have simple blocks that just renders a few properties then avoid using a separate controller.
If you have plenty of logic that you need to take care of for the block, external data sources etc, then use a separate controller instead of making the poor views/html helpers have too much to worry about.
So both are good ideas; Just depends on how advanced your block is...
If you switch from non-controller approach to controller approach -> sometimes you may wonder why your controller is not hit. Remember that EPiServer is using conventions to register templates for each content type. If there will be "reachable" template with the same name as your block type name -> your controller most probably will not be hit and EPiServer will skip that -> going directly to template.
Also - it's not necessary to have folder with block name and index.cshtml inside. What we are usually doing for blocks (it's subjective choice) - we do have templates "_{block-name}.cshtml" (_MyBlock.cshtml). This will make sure that EPiServer is not picking up template automatically.
From my memory, the block without controller has better performance. If your view only need to render that block data, personally, I would go with no controller approach.
It really depends on complexity of the block logic. Sometimes there is no way to avoid controller for the block. But yes, you are true - invoking controller for the block costs more that dumb generation of the renderer template for the block.
Yup, better performance without controller and if you have a partial view you get perfect out of the box support for wysiwyg in edit mode as well. Otherwise you will need a little more tricks to get Ajax updates of blocks in edit mode to work...
Question: if you don't have a controller for the block, when you try to view the block (and not the page) in edit mode, you get a YSOD.
Any way to resolve this?
Yeah I have a preview controller - just cracked it, it was because the view for my preview controller was in the wrong place
Hi James,
Where was the view when it was in the wrong place, and where should it have been? I had trouble with preview before.
Marshall
I want to create a block with two or three properties.
I just want to know the difference between a block with and without controller. A block created without controller has the view (with block name) under shared folder, however for the one with controller we will have a separate folder with Block Name and Index view in it.
Could anyone please list out which one is preferable and why?