Try our conversational search powered by Generative AI!

Check if Block is in editmode?


How is it possible to check if a block is open in the editor and I also want to check if the block is viewed in a content area on a page in the editor?

Im having an issue with my blocks where it is rendered fine when viewed only for the block in the editor, but when the page is viewed where the block is inserted I get some other data from the block that are specific for the block-editor and that I don't want to render when viewing the page in the editor.

I know how to check if a page is in editormode by using: EPiServer.Editor.PageEditing.PageIsInEditMode

But that dosen't seem to work for me.

Feb 19, 2014 14:09

You could add this to your action in your  preview controller:

ViewBag.BlockPreview = true;


And then in your view, instead of using PageEditing.PageIsInEditMode, you use

@if(ViewBag.BlockPreview == true)



Feb 19, 2014 14:56

Sorry I forgot to say, My project is in webforms. Any tip for that? :)

Feb 19, 2014 15:56

Assuming you have a model called PreviewPage, you could try:


if (Page is PreviewPage)



Edit: Capital P

Edited, Feb 19, 2014 16:15

Works great! Thanks!

Feb 20, 2014 8:06

Thanks exactly what i needed


Sep 23, 2014 15:47

Thanks Per Magne

Your ViewBag.BlockPreview = true was a nice solution for my mvc project.

Feb 26, 2015 0:20
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.