0

I am wondering if there is a way to set a class to a container div ONLY if in edit mode in EPiServer? I found this way to add a html-element:

@if (PageEditing.PageIsInEditMode) {
    <p>I am in edit mode!</p>
}

But is there a way to do like this:

<div class="main-content @PageEditing.PageIsInEditMode ? 'edit-mode' : 'not-edit-mode'">
    Lots of content here
</div>

For me that renders as:

<div class="main-content class ? 'edit-mode' : 'not-edit-mode'">

But there has to be a clever way to make this work?

noodle
  • 5
  • 2

1 Answers1

0

You have to put parenthesis around it for the whole expression to be parsed, otherwise Razor stops parsing as soon as it can:

@(PageEditing.PageIsInEditMode ? "edit-mode" : "not-edit-mode")
Jesper
  • 7,477
  • 4
  • 40
  • 57
  • Ah is that so! It still renders an error though, it just tells me an error occurred on the page. Visual Studio doesn't like the class names 'edit-mode' and 'not-edit-mode', and tells me "Bad compile constant value". – noodle May 07 '15 at 08:52
  • You're right, I didn't fix that error. You have to use double quotes around strings in C#. Single quotes are for single-character `char` values. – Jesper May 07 '15 at 09:00