Skip to content

Attributes

Visible Attribute

namespace: Serenity.ComponentModel, assembly: Serenity.Core

Controls visibility of a column or form field.

It is also possible to hide a field by passing false as its value, but [Hidden] attribute is recommended.

public class SomeColumns
{
    [Visible]
    public string? ExplicitlyVisible { get; set; }
    [Visible(false)]
    public string? ExplicitlyHidden { get; set; }
}
  • User might still show the column by using the column picker if any.

Hidden Attribute

namespace: Serenity.ComponentModel, assembly: Serenity.Core

Hides a column or form field.

This is just a subclass of VisibleAttribute with false value.

public class SomeColumns
{
    [Hidden]
    public string? HiddenColumn { get; set; }
}
  • User might still show the column by using the column picker if any.

HideOnInsert Attribute

namespace: Serenity.ComponentModel, assembly: Serenity.Core

Controls whether a field is visible on new record mode.

  • This only works with forms, not columns.
public class SomeColumns
{
    [HideOnInsert]
    public string? HideMeOnInsert { get; set; }
    [HideOnInsert(false)]
    public string? DontHideMeOnInsert { get; set; }
}

HideOnUpdate Attribute

namespace: Serenity.ComponentModel, assembly: Serenity.Core

Controls whether a field is visible on edit record mode.

  • This only works with forms, not columns.
public class SomeColumns
{
    [HideOnUpdate]
    public string? HideMeOnUpdate { get; set; }
    [HideOnUpdate(false)]
    public string? DontHideMeOnUpdate { get; set; }
}

Insertable Attribute

namespace: Serenity.ComponentModel, assembly: Serenity.Core

Controls if a property is editable in new record mode.

  • When used on row fields, turns on or off the Insertable flag.

  • It has no effect on columns

public class SomeForm
{
    [Insertable(false)]
    public string? ReadOnlyOnInsert { get; set; }
}

Updatable Attribute

namespace: Serenity.ComponentModel, assembly: Serenity.Core

Controls if a property is editable in edit record mode.

  • When used on row fields, turns on or off the Updatable flag.

  • It has no effect on columns

public class SomeForm
{
    [Updatable(false)]
    public string? ReadOnlyOnUpdate { get; set; }
}

DisplayText Attribute

namespace: Serenity.ComponentModel, assembly: Serenity.Core

Determines default title for grid columns or form fields.

public class SomeForm
{
    [DisplayText("Title for Some Field")]
    public string? SomeField { get; set; }
}
  • DisplayText attribute cannot be used on Enum members, so you have to use DescriptionText attribute

  • Titles set with this attribute is considered to be in invariant language.

  • Unlike DisplayName, the string passed to DisplayText is never interpreted as a local text key. A key-looking value such as [DisplayText("Db.Shared.RecordId")] is still literal invariant text. Use TextKey when you want a key:

[DisplayText("Movie Name", TextKey = "Movie.MovieName")] // key plus invariant fallback text
[DisplayText(TextKey = "Db.Shared.RecordId")]            // key only, no literal text
  • This is what sergen emits for generated columns (e.g. [DisplayText(TextKey = "Db.Shared.RecordId")] for the ID column).

  • When neither TextKey nor a text is given, the text of a property or a column takes the key that its type implies, e.g. Forms.MyForm.CompanyName or Columns.MyColumns.CompanyName, and is registered with its text, so it is translated without a change to the code.

  • An empty TextKey, i.e. LocalText.Literal, means the text is not a local text key, e.g. for a text that is a name: it is shown as it is, and neither used as a key nor registered under the implied one. This is the way to keep a text out of the local texts:

[DisplayText("Acme Corporation", TextKey = LocalText.Literal)] // shown as it is, not translated
[DisplayText(CompanyNameTexts.Acme)] // a key from a NestedLocalTexts class, the usual way

The same applies to the other attributes that take a TextKey, i.e. DescriptionText, CategoryName, Hint, Placeholder, Tab, InstanceName, the validation attributes, and the items of a select editor (SelectItem). As a key can only be set in an attribute, an empty one is always deliberate: the text is not a key, and it is not registered. The members of an enum, a StringEnum included, work the same way: the client gets the key that a member declares, or its literal text, with the enum itself.

This is a subclass of System.ComponentModel.DisplayNameAttribute

DescriptionText Attribute

namespace: Serenity.ComponentModel, assembly: Serenity.Core

Determines default title for enum members.

public class SomeEnum
{
    [DescriptionText("Title for Value 1")]
    Value1 = 1,
    [DescriptionText("Value 2")]
    Value2 = 2
}
  • Titles set with this attribute is considered to be in invariant language.

  • Like DisplayText, it supports an explicit TextKey; the value itself is never inferred as a key:

[DescriptionText("Access denied", TextKey = "Site.AccessDenied")]

This is a subclass of System.ComponentModel.DescriptionAttribute

CategoryName Attribute

namespace: Serenity.ComponentModel, assembly: Serenity.Core

Sets the category (form tab or grid grouping category) for a property or class, with explicit local text key support:

[CategoryName("General", TextKey = "Movie.GeneralCategory")]
public class MovieForm
{
}
  • CategoryName is the explicit-key counterpart of System.ComponentModel.CategoryAttribute. The value is treated as literal invariant text unless TextKey is set.

  • It can also be used key-only, e.g. [CategoryName(TextKey = "Movie.GeneralCategory")].

This is a subclass of System.ComponentModel.CategoryAttribute

DisplayFormat Attribute

namespace: Serenity.ComponentModel, assembly: Serenity.Core

Sets the display format for a column.

  • This has no effect on editors! It is only for Display, NOT Editing. For editing, you have to change culture in web.config (not UI culture).

  • Display format strings are specific to column data and formatter type.

  • If column is a Date or DateTime column, its default formatter accepts custom DateTime format strings like dd/MM/yyyy.

  • We don't suggest setting DisplayFormat for dates explicitly, use culture setting (not UI culture) in web.config unless a column has to display date/time in a different order than the default.

  • You may also use following standard format strings:

    • "d": dd/MM/yyyy where DMY order changes based on current culture.
    • "g": dd/MM/yyyy HH:mm where DMY order changes based on current culture.
    • "G": dd/MM/yyyy HH:mm:ss where DMY order changes based on current culture.
    • "s": yyydd-MM-ddTHH:mm:ss ISO sortable date time format.
    • "u": yyydd-MM-ddTHH:mm:ss.fffZ ISO 8601 UTC.
  • If column is an integer, double or decimal it accepts .NET custom numeric format strings.

public class SomeColumns
{
    [DisplayFormat("d")]
    public DateTime? DateWithCultureDMYOrder { get; set; }
    [DisplayFormat("dd/MM/yyyy")]
    public DateTime? DateWithConstantDMYOrder { get; set; }
    [DisplayFormat("g")]
    public DateTime? DateTimeToMinWithCultureDMYOrder { get; set; }
    [DisplayFormat("dd/MM/yyyy HH:mm")]
    public DateTime? DateTimeToMinConstantDMYOrder { get; set; }
    [DisplayFormat("G")]
    public DateTime? DateTimeToSecWithCultureDMYOrder { get; set; }
    [DisplayFormat("dd/MM/yyyy HH:mm:ss")]
    public DateTime? DateTimeToSecWithConstantDMYOrder { get; set; }
    [DisplayFormat("s")]
    public DateTime? SortableDateTime { get; set; }
    [DisplayFormat("u")]
    public DateTime? ISO8601UTC { get; set; }
    [DisplayFormat("#,##0.00")]
    public Decimal? ShowTwoZerosAfterDecimalWithGrouping { get; set; }
    [DisplayFormat("0.00")]
    public Decimal? ShowTwoZerosAfterDecimalNoGrouping { get; set; }
}

Placeholder Attribute

namespace: Serenity.ComponentModel, assembly: Serenity.Core

Sets a placeholder for a form field.

  • Placeholder is shown inside the editor with gray color when editor value is empty.
  • Only basic input based editors and Select2 supports this. It is ignored by other editor types like Checkbox, Grid, FileUploadEditor etc.
public class SomeForm
{
    [Placeholder("Show this inside the editor when it is empty")]
    public string? FieldWithPlaceHolder { get; set; }
}
  • The string is always literal text. To localize the placeholder, set TextKey:
[Placeholder(TextKey = "Movie.Title.Placeholder")]
public string? Title { get; set; }

Hint Attribute

namespace: Serenity.ComponentModel, assembly: Serenity.Core

Sets a hint for a form field.

  • Hint is shown when field label is hovered.

  • This has no effect on columns.

public class SomeForm
{
    [Hint("Show this when my caption is hovered")]
    public string? FieldWithHint { get; set; }
}
  • As with Placeholder, the value is literal text; use TextKey to localize it (e.g. [Hint(TextKey = "Movie.Title.Hint")]). The same applies to Tab and InstanceName.

CssClass Attribute

namespace: Serenity.ComponentModel, assembly: Serenity.Core

Sets CSS class for grid columns and form fields.

  • In forms, class is added to container div with .field class that contains both label and editor.

  • For columns, it sets cssClass property of SlickColumn, which adds this class to slick cells for all rows.

  • Slick column headers are not affected by this attribute, use [HeaderCssClass] for that.

public class SomeForm
{
    [CssClass("extra-class")]
    public string? FieldWithExtraClass { get; set; }
}

public class SomeColumn
{
    [CssClass("extra-class")]
    public string? CellWithExtraClass { get; set; }
}

HeaderCssClass Attribute

namespace: Serenity.ComponentModel, assembly: Serenity.Core

Sets CSS class for grid column headers.

  • This has no effect for forms.

  • It sets headerCss property of SlickColumn, which adds this class to slick header for that column.

public class SomeColumn
{
    [HeaderCssClass("extra-class")]
    public string? FieldWithExtraHeaderClass { get; set; }
}

AlignCenter Attribute

namespace: Serenity.ComponentModel, assembly: Serenity.Core

Centers text horizontally.

  • Used to control text alignment in grids by adding align-center CSS class to corresponding SlickGrid column.

  • Column headers are not affected by this attribute. You may use [HeaderCssClass("align-center")] for that.

  • Note that it has no effect on editors or forms.

AlignRight Attribute

namespace: Serenity.ComponentModel, assembly: Serenity.Core

Right aligns text horizontally.

  • Used to control text alignment in grids by adding align-right CSS class to corresponding SlickGrid column.

  • Column headers are not affected by this attribute. You may use [HeaderCssClass("align-right")] for that.

  • Note that it has no effect on editors or forms.

Ignore Attribute

namespace: Serenity.ComponentModel, assembly: Serenity.Core

Skips a property while generating grid column or form field list.

  • Use this to ignore a property for UI, but still use it for other purposes like JSON serialization.

  • This might be useful when a type is used as a Service Request and Form Declaration at the same time.

public class SomeColumns
{
    [Ignore]
    public string? DontGenerateAColumnForMe { get; set; }
}