To hide a property in Episerver, you can use the ScaffoldColumn
attribute in your model class. This attribute controls whether a property should be displayed in forms or tables generated by the Episerver CMS UI.
Here's an example of how to use the ScaffoldColumn
attribute to hide a property:
csharpusing EPiServer.Core;
using EPiServer.DataAnnotations;
public class MyPageType : PageData
{
[Display(
Name = "My Visible Property",
Description = "This property is visible.",
Order = 1
)]
public string MyVisibleProperty { get; set; }
[ScaffoldColumn(false)]
public string MyHiddenProperty { get; set; }
}
In this example, the MyHiddenProperty
is marked with the ScaffoldColumn
attribute with a value of false
. This indicates to the Episerver CMS UI that this property should not be displayed in forms or tables.
When an editor views the form for creating or editing a page of MyPageType
, the MyHiddenProperty
will not be displayed in the UI. Editors can still access and modify the value of this property programmatically, but it will not be visible in the CMS UI.
Note that the ScaffoldColumn
attribute is used to control the display of a property in Episerver forms and tables, but it does not affect whether the property is visible or editable in the generated HTML of a page or template. If you need to prevent a property from being rendered in HTML, you'll need to use a different approach, such as excluding it from the view model or adding additional checks in the view.
Comments
Post a Comment