---
title: Defining section properties
related:
  - https://docs.kentico.com/k12sp/developing-websites/page-builder-development.md
  - https://docs.kentico.com/k12sp/developing-websites/page-builder-development/creating-pages-with-editable-areas-in-mvc.md
  - https://docs.kentico.com/k12sp/developing-websites/page-builder-development/developing-page-builder-sections.md
  - https://docs.kentico.com/k12sp/multilingual-websites/setting-up-a-multilingual-user-interface/localizing-mvc-builder-components.md
  - https://docs.kentico.com/k12sp/managing-website-content/using-widgets-in-mvc.md
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

When developing [page builder sections](https://docs.kentico.com/k12sp/developing-websites/page-builder-development/developing-page-builder-sections.md), you can define properties that allow content editors to adjust the appearance or behavior of the sections in the Kentico administration interface. Users then interact with the section properties through section configuration dialogs.

Use the following process to develop properties for a section:

1. [Create a model class that defines the section properties](#creating-property-models)
2. [Define the configuration dialog to allow content editors to modify the properties](#defining-the-configuration-dialog)
3. [Handle the properties in the section's code](#handling-properties-in-section-code)

See the [Example](#example---developing-a-section-with-a-configurable-property) on this page for a scenario with full code samples.

## Creating property models

The properties of a section must be defined within a model class that implements the **ISectionProperties** interface (available in the **Kentico.PageBuilder.Web.Mvc** namespace).

Specify each section property by creating a corresponding property in the model class. You can also set default values for the properties.

```csharp title="Example"

public class CustomSectionProperties : ISectionProperties
{
    // Defines a property and sets its default value
    public string Color{ get; set; } = "#FFF";
}

```

> **Tip:** You can use the _Newtonsoft.Json.JsonIgnore_ attribute to exclude dynamically computed section properties from database serialization.

We recommend storing section property models in the _\~/Models/Sections/_ folder.

## Defining the configuration dialog

The configuration dialog is a simple way to allow content editors to set values for section properties. In the property model class, you need to define editing form components for section properties which you want to make editable in the configuration dialog. You can use the system's [default form components](https://docs.kentico.com/k12sp/developing-websites/form-builder-development/reference-system-form-components.md) or develop [custom form components](https://docs.kentico.com/k12sp/developing-websites/form-builder-development/developing-form-components.md).

1. Edit the section's property model class in your MVC project.
2. Define the visual interface of the configuration dialog:

   - Decorate the appropriate properties using the **EditingComponent** attribute (available in the _Kentico.Forms.Web.Mvc_ namespace).
   - The attribute assigns and configures a [form component](https://docs.kentico.com/k12sp/developing-websites/form-builder-development/reference-system-form-components.md), which is used as the input element for the given property in the configuration dialog.

     > **Note:** **Note**: To learn about the available options when using and configuring editing components for properties, see [Assigning editing components to properties](https://docs.kentico.com/k12sp/developing-websites/form-builder-development/assigning-editing-components-to-properties.md).

```csharp title="Example - Setting an editing component"

[EditingComponent(TextInputComponent.IDENTIFIER, Order = 0, Label = "Color")]
public string Color { get; set; } = "#FFF";

```

Users can now click the **Configure** () icon when [working with sections in the Kentico administration interface](https://docs.kentico.com/k12sp/managing-website-content/using-widgets-in-mvc.md). This opens the section properties dialog, and the configured property values affect the appearance and functionality of the section on the live site.

> **Tip:** **Tip**: If you need to create advanced property editors, you can implement [modal dialogs](https://docs.kentico.com/k12sp/developing-websites/page-builder-development/developing-modal-dialogs-for-builder-component-properties.md). This allows users to set the section property's value in a custom dialog (a new window separate from the configuration dialog).

## Handling properties in section code

In order for properties to have an effect on a section's appearance or functionality, you need to retrieve the property values and adjust the section's output code or logic correspondingly. The required steps depend on the development approach used to create the section (see [Developing page builder sections](https://docs.kentico.com/k12sp/developing-websites/page-builder-development/developing-page-builder-sections.md) for more information).

### Basic sections

For sections without a custom controller class, handle the property values in the section's partial view.

The view must use the generic **ComponentViewModel** class as its model, with the appropriate property model class as the generic type parameter. The system's default controller ensures that the property values configured for the currently processed section are passed to the view. Retrieve the property values from the model's **Properties** member, which returns an object of the specified property model class.

```xml title="Example"

@using Kentico.PageBuilder.Web.Mvc
@using Kentico.Web.Mvc

@model ComponentViewModel<CustomSectionProperties>

<div style="background-color: @Model.Properties.Color;">
    @Html.Kentico().WidgetZone()
</div>

```

### Sections with a custom controller

To work with properties in your section controllers, the controller class must inherit from the generic **SectionController** base class, with the appropriate property model class as the generic type parameter.

```csharp

public class CustomSectionController : SectionController<CustomSectionProperties>


```

Retrieve the properties as a strongly typed object by calling the **GetProperties** method (provided by the base class). The method returns an object of the specified property model class. The object's property values are loaded from the current configuration of the processed section.

```csharp

// Gets the value of a section property
CustomSectionProperties sectionProperties = GetProperties();
string propertyValue = sectionProperties.Color;

```

> **Note:** **Note**: The **GetProperties** method only works correctly in controller actions that handle GET requests. You cannot use the method in POST actions, which lack the context of the current page and section instance.

You can then adjust the code of your controller based on the values of individual section properties, or pass them to the section's view using an appropriate view model.

Do not directly pass the property model to your section views. We strongly recommend creating a separate view model class, which you can then use to pass data to the section view.

## Example - Developing a section with a configurable property

The following scenario will guide you through a step-by-step process of developing a simple [page builder section](https://docs.kentico.com/k12sp/developing-websites/page-builder-development/developing-page-builder-sections.md) with a configurable property.

When finished, the section is displayed with a color background of your choice. The color is set via a section property and can be modified through a section configuration dialog. The color can be specified in any text format that is accepted by the [CSS background-color property](https://www.w3schools.com/cssref/pr_background-color.asp) (e.g. a HEX or RGB value).

> **Note:** **Note**: The following example is based on the [LearningKit project](https://github.com/Kentico/LearningKit-Mvc). To use the code samples in your project, you need to modify the namespaces, identifiers and other occurrences where _LearningKit_ is mentioned to match your project's name.

### Property model

Create a properties model **CustomSectionProperties.cs** in the _\~/Models/Sections/CustomSection_ folder:

```csharp

using Kentico.Forms.Web.Mvc;
using Kentico.PageBuilder.Web.Mvc;

namespace LearningKit.Models.Sections.CustomSection
{
    public class CustomSectionProperties : ISectionProperties
    {
        // Defines a property and sets its default value
        // Assigns the default Kentico text input component, which allows users to enter
        // a string value for the property in the section's configuration dialog
        [EditingComponent(TextInputComponent.IDENTIFIER, Order = 0, Label = "Color")]
        public string Color { get; set; } = "#FFF";

    }
}

```

### Partial view

Create a partial view **\_CustomSection.cshtml** in the _\~/Views/Shared/Sections_ folder:

```csharp

@using Kentico.PageBuilder.Web.Mvc
@using Kentico.Web.Mvc

@using LearningKit.Models.Sections.CustomSection

@model ComponentViewModel<CustomSectionProperties>

@* Shows a sample section with a background color specified in the section's configuration dialog *@
<div style="background-color: @Model.Properties.Color;">
    @Html.Kentico().WidgetZone()
</div>

```

### Section registration

Register the section into the system using the **RegisterSection** assembly attribute. We recommend adding a dedicated code file to your project's _\~/App\_Start_ folder for the purposes of component registration, for example named **PageBuilderComponentRegister.cs**.

```csharp

using LearningKit.Models.Sections.CustomSection;

using Kentico.PageBuilder.Web.Mvc;

// Registers the 'Custom section' section (it uses the system's default controller and ComponentViewModel)
[assembly: RegisterSection("LearningKit.Sections.CustomSection",
                          "Custom section",
                          typeof(CustomSectionProperties),
                          customViewName: "Sections/_CustomSection",
                          IconClass = "icon-square")]

```
