November Happy Hour will be moved to Thursday December 5th.

Check if Block is in editmode?

Vote:
 

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.

#81564
Feb 19, 2014 14:09
Vote:
 

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

    

 



#81565
Feb 19, 2014 14:56
Vote:
 

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

#81570
Feb 19, 2014 15:56
Vote:
 

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

 

if (Page is PreviewPage)
{

}

    

Edit: Capital P

#81573
Edited, Feb 19, 2014 16:15
Vote:
 

Works great! Thanks!

#81585
Feb 20, 2014 8:06
Vote:
 

Thanks exactly what i needed


Minesh

#90997
Sep 23, 2014 15:47
Vote:
 

Thanks Per Magne

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

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