Skip to main content

MVCxFormLayoutItemCollection.Add(Action<MVCxFormLayoutItem>) Method

Adds a new layout item to the collection and allows you to customize this layout item in a delegate method implementation.

Namespace: DevExpress.Web.Mvc

Assembly: DevExpress.Web.Mvc5.v24.1.dll

NuGet Package: DevExpress.Web.Mvc5

Declaration

public MVCxFormLayoutItem Add(
    Action<MVCxFormLayoutItem> method
)

Parameters

Name Type Description
method Action<MVCxFormLayoutItem>

A delegate method that accepts the created MVCxFormLayoutItem as a parameter.

Returns

Type Description
MVCxFormLayoutItem

A MVCxFormLayoutItem object that is the newly added layout item.

Remarks

If an item type (specified using the MVCxFormLayoutItem.NestedExtensionType property) is not set explicitly, the FormLayout creates a default item, applies your settings to it and uses a corresponding model property to determine a required type. Once the type is determined, the default Layout item is removed, and another item or a required type is created. Note that in this scenario, the FormaLayout gets access to the Model only during data binding, at which time your settings have been already applied to the default item. So, they do not apply to the new item again.

To solve this issue, you can do the following.

  1. Declare item type in item settings explicitly:

    groupSettings.Items.Add(itemSettings => {
        itemSettings.FieldName = "Description";
         itemSettings.NestedExtensionType = FormLayoutNestedExtensionItemType.TextBox; //required type here
        itemSettings.NestedExtensionSettings.Width = Unit.Percentage(100);
    });
    
  2. Alternatively, use the overloaded Add method that directly accepts a Model property:

    groupSettings.Items.Add(m => m.Description, itemSettings =>
    {
        itemSettings.FieldName = "Description";
        itemSettings.NestedExtensionSettings.Width = Unit.Percentage(100);
    });
    
See Also