---
title: Defining widget properties
related:
  - https://docs.kentico.com/13/developing-websites/page-builder-development.md
  - https://docs.kentico.com/13/developing-websites/page-builder-development/developing-widgets.md
  - https://docs.kentico.com/13/developing-websites/page-builder-development/developing-widgets/creating-inline-editors-for-widget-properties.md
  - https://docs.kentico.com/13/developing-websites/page-builder-development/developing-modal-dialogs-for-builder-component-properties.md
  - https://docs.kentico.com/13/multilingual-websites/setting-up-a-multilingual-user-interface/localizing-builder-components.md
  - https://docs.kentico.com/13/managing-website-content/adding-page-content-using-widgets.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 widgets](https://docs.kentico.com/13/developing-websites/page-builder-development/developing-widgets.md), you can define properties that allow content editors to adjust the widget content or behavior directly in the administration interface. Users interact with widget properties through the widget configuration dialog or inline editors, which you need to implement.

Use the following process to develop properties for a widget:

1. [Create a model class that defines the widget properties](#creating-property-models).

2. Allow content editors to modify the widget properties:

   - [Define the configuration dialog](#defining-the-configuration-dialog)
   - [Implement inline editors](https://docs.kentico.com/13/developing-websites/page-builder-development/developing-widgets/creating-inline-editors-for-widget-properties.md)

   > **Tip:** **Configuration dialog and inline editors**
   >
   > You can combine the configuration dialog and inline editors in a single widget.

3. [Handle the properties in the widget's code](#handling-properties-in-widget-code).

4. (Optional) [Add support for POST actions](#accessing-widget-properties-in-post-actions).

To see a scenario with full code samples which will guide you through the process of developing a simple widget with a property, visit [Example - Developing a widget](https://docs.kentico.com/13/developing-websites/page-builder-development/developing-widgets/example-developing-a-widget.md).

> **Note:** **Areas**
>
> Widgets are designed as global components. Adding related files, such as property model classes, into Areas is not supported and may lead to unexpected behavior.

## Creating property models

<!-- dev-model:mvc start -->

**MVC 5 development model.** Applies only when building with ASP.NET MVC 5. If this page also covers ASP.NET Core, that version is in its own block.

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

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

```csharp title="Example"

public class CustomWidgetProperties : IWidgetProperties
{
    // Defines a property and sets its default value
    public int Number { get; set; } = 22;
}

```

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

We recommend storing widget property models in the _\~/Models/Widgets/_ folder.

<!-- dev-model:mvc end -->

<!-- dev-model:core start -->

**ASP.NET Core development model.** Applies only when building with ASP.NET Core. If this page also covers MVC 5, that version is in its own block.

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

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

```csharp

    public class CustomWidgetProperties : IWidgetProperties
    {
        // Defines a property and sets its default value
        public int Number { get; set; } = 22;
    }


```

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

We recommend storing widget property models in the _\~/Components/Widgets/_ folder together with other files required by the widget.

<!-- dev-model:core end -->

## Defining the configuration dialog

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

<!-- dev-model:mvc start -->

**MVC 5 development model.** Applies only when building with ASP.NET MVC 5. If this page also covers ASP.NET Core, that version is in its own block.

1. Edit the widget'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/13/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/13/developing-websites/form-builder-development/assigning-editing-components-to-properties.md).

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

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

   ```

<!-- dev-model:mvc end -->

<!-- dev-model:core start -->

**ASP.NET Core development model.** Applies only when building with ASP.NET Core. If this page also covers MVC 5, that version is in its own block.

1. Edit the widget's property model class in your Core 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/13/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/13/developing-websites/form-builder-development/assigning-editing-components-to-properties.md).

   ```csharp

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

   ```

<!-- dev-model:core end -->

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

> **Tip:** **Advanced property options**
>
> - You can add dynamic [visibility conditions](https://docs.kentico.com/13/developing-websites/form-builder-development/adding-visibility-conditions-for-builder-component-properties.md) that restrict how and when properties are displayed in the widget configuration dialog.
> - If you need to create advanced property editors, you can implement [modal dialogs](https://docs.kentico.com/13/developing-websites/page-builder-development/developing-modal-dialogs-for-builder-component-properties.md). This allows users to set the widget property's value in a custom dialog (a new window separate from the configuration dialog).

## Handling properties in widget code

For properties to have an effect on a widget's appearance or functionality, you need to retrieve their values and reflect them in the widget's output code or logic. The required steps depend on the development approach used to create the widget (see [Developing widgets](https://docs.kentico.com/13/developing-websites/page-builder-development/developing-widgets.md) for more information).

<!-- dev-model:mvc start -->

**MVC 5 development model.** Applies only when building with ASP.NET MVC 5. If this page also covers ASP.NET Core, that version is in its own block.

### Basic widgets

For basic widgets without a custom controller class, handle the property values in the widget'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 widget 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

@model ComponentViewModel<CustomWidgetProperties>

<p>The value of the widget's 'Number' property is: @Model.Properties.Number</p>

```

### Widgets with a custom controller

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

```csharp

public class CustomWidgetController : WidgetController<CustomWidgetProperties>

```

Retrieve the properties as a strongly typed object via the **IComponentPropertiesRetriever** service (_Kentico.PageBuilder.Web.Mvc_ namespace) and its **Retrieve** method. 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 widget.

```csharp

// Contains an instance of the IComponentPropertiesRetriever service (e.g., obtained via dependency injection).
private readonly IComponentPropertiesRetriever componentPropertiesRetriever;

// Gets the value of a widget property (e.g. within the widget controller's Index action)
CustomWidgetProperties properties = componentPropertiesRetriever.Retrieve<CustomWidgetProperties>();
int propertyValue = properties.Number;

```

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

> **Info:** Do not directly pass the property model to your widget views. Passing data to views is the responsibility of the widget's view model, and we strongly recommend keeping the logic separate.

<!-- dev-model:mvc end -->

<!-- dev-model:core start -->

**ASP.NET Core development model.** Applies only when building with ASP.NET Core. If this page also covers MVC 5, that version is in its own block.

### Basic widgets

For basic widgets that consist only of a partial view file and a properties class, handle the property values in the widget'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 ensures that property values configured for the currently processed widget 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

@model ComponentViewModel<CustomWidgetProperties>

<p>The value of the widget's 'Number' property is: @Model.Properties.Number</p>

```

### Widgets based on a view component

To work with widget properties in view components, the component's _Invoke_ or _InvokeAsync_ method signature must declare the **ComponentViewModel** parameter, with the appropriate property model class as the generic type.

```csharp

// The signature of a view component's InvokeAsync method for widgets with custom properties
public Task<IViewComponentResult> InvokeAsync(ComponentViewModel<CustomWidgetProperties> widgetProperties)

```

The widget's properties are accessible via the **Properties** property of the _ComponentViewModel_ parameter, which contains an object of the specified property model class. The property values are loaded from the current configuration of the processed widget.

```csharp

// Gets the value of a widget property from within a component's Invoke method
int propertyValue = widgetProperties.Properties.Number;

```

You can then adjust the flow of your logic based on the values of various properties, or pass them to the component's view using an appropriate view model.

> **Info:** Do not directly pass the property model to your widget views. Passing data to views is the responsibility of the widget's view model, and we strongly recommend keeping the models separate.

<!-- dev-model:core end -->

## Accessing widget properties in POST actions

<!-- dev-model:mvc start -->

**MVC 5 development model.** Applies only when building with ASP.NET MVC 5. If this page also covers ASP.NET Core, that version is in its own block.

Widget properties cannot be automatically retrieved during POST requests. Common POST requests do not contain sufficient information to identify the page and widget instance from which they originate.

To retrieve widget properties in POST actions, you first need to include the properties into the data submitted by the corresponding HTML form in the widget's output. Call the **Html.Kentico().ComponentPropertiesData** extension method within the given form tag in your widget view.

```csharp title="Example"

using System.Web.Mvc.Ajax
using Kentico.Web.Mvc
using Kentico.PageBuilder.Web.Mvc

...

@using (Ajax.BeginForm("PostAction", "CustomWidget", null, new AjaxOptions
{
    HttpMethod = "POST",
    UpdateTargetId = "widgetForm"
}, new { id = "widgetForm" }))
{
    @Html.Kentico().AntiForgeryToken()
    @Html.Kentico().ComponentPropertiesData()
    ...
    <input type="submit" value="Submit" />
}

```

The method renders a hidden field that persists the widget's properties and makes them available via the properties retriever in the targeted controller action.

<!-- dev-model:mvc end -->

<!-- dev-model:core start -->

**ASP.NET Core development model.** Applies only when building with ASP.NET Core. If this page also covers MVC 5, that version is in its own block.

Basic POST requests do not by default contain widget properties data. To access the properties of a widget during POST actions (in the [controller class](https://docs.kentico.com/13/developing-websites/page-builder-development/developing-widgets.md#handling-post-actions) handling POST requests), you first need to include the properties into the data submitted by the corresponding HTML form in the widget's output. Call the **Html.Kentico().ComponentPropertiesData** extension method (or its [Tag Helper](https://docs.kentico.com/13/developing-websites/developing-xperience-applications-using-asp-net-core/reference-xperience-tag-helpers.md) equivalent) within the given form tag in your widget view.

```xml title="Example"

using Kentico.Content.Web.Mvc

...

<form asp-controller="WidgetPostController" asp-action="HandlePost" method="post">
    ...

    @Html.Kentico().ComponentPropertiesData()

    <input type="submit" value="Submit" />
</form>

```

The method renders a hidden field that persists the widget's current properties configuration.

On the server, access the widget's properties in the corresponding controller class via the **IComponentPropertiesRetriever** service and its **Retrieve** method. Specify the widget's properties class as the method's generic parameter:

```csharp title="Controller class handling the request"

// Contains an instance of the IComponentPropertiesRetriever service (e.g., obtained via dependency injection)
private readonly IComponentPropertiesRetriever componentPropertiesRetriever;

// Gets the properties of the widget as a strongly typed object 
NumberWidgetProperties properties = componentPropertiesRetriever.Retrieve<NumberWidgetProperties>();

```

<!-- dev-model:core end -->
