How To Hide A Property In Episerver CMS And How To Make A Property ReadOnly

Over the years, I’ve often needed to do various things to a property, like make a property read only, or, to hide it from content editors completely. Luckily Episerver provides us some handy attributes to help us.

Hiding A Property

This can be done by adding the [Ignore] attributes on top of your properties, like so:

[Ignore]
public int HiddenPrimaryKey { get; set; }

Adding this attribute to your property will allow you to save data to the property in code but a content editor will never see it within Episerver.

Making a read-only property

The next attribute in our Episerver toolkit is the read-only attribute.  Adding this to a property will show it in the Episerver editor but it will be greyed out and the content editor won’t be able to edit it.

[Display(Name="Readonly Property")]
[Editable(false)]
public virtual string ReadonlyProperty {get;set; }

An alternative way of hiding a property in edit mode

[ScaffoldColumn(false)]
public object HiddenProperty { get; set; }

An alternative way of hiding a property is using the [ScaffoldColumn] attribute. When ScaffoldColumn is set to false, the ScaffoldColumn will hide the property from editors.  In Episerver language to scaffold a property means that a content editor may be able to see the rendered value in preview mode, they won’t see the blue editable box around it and they won’t be able to click on the property to edit it. The property won’t be visible in forms editing mode either.

Jon D Jones

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge

More Posts

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *