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.

  1. public class SomeColumns
  2. {
  3. [Visible]
  4. public string ExplicitlyVisible { get; set; }
  5. [Visible(false)]
  6. public string ExplicitlyHidden { get; set; }
  7. }
  • 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.

  1. public class SomeColumns
  2. {
  3. [Hidden]
  4. public string HiddenColumn { get; set; }
  5. }
  • 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.
  1. public class SomeColumns
  2. {
  3. [HideOnInsert]
  4. public string HideMeOnInsert { get; set; }
  5. [HideOnInsert(false)]
  6. public string DontHideMeOnInsert { get; set; }
  7. }

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.
  1. public class SomeColumns
  2. {
  3. [HideOnUpdate]
  4. public string HideMeOnUpdate { get; set; }
  5. [HideOnUpdate(false)]
  6. public string DontHideMeOnUpdate { get; set; }
  7. }

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

  1. public class SomeForm
  2. {
  3. [Insertable(false)]
  4. public string ReadOnlyOnInsert { get; set; }
  5. }

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

  1. public class SomeForm
  2. {
  3. [Updatable(false)]
  4. public string ReadOnlyOnUpdate { get; set; }
  5. }

DisplayName Attribute

namespace: System.ComponentModel, assembly: System

Determines default title for grid columns or form fields.

  1. public class SomeForm
  2. {
  3. [DisplayName("Title for Some Field")]
  4. public string SomeField { get; set; }
  5. }
  • DisplayName attribute cannot be used on Enum members, so you have to use
    Description attribute

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

This is not a Serenity attribute, it resides in .NET System assembly.

Description Attribute

namespace: System.ComponentModel, assembly: System

Determines default title for enum members.

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

This is not a Serenity attribute, it resides in .NET System assembly.

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.

  1. public class SomeColumns
  2. {
  3. [DisplayFormat("d")]
  4. public DateTime DateWithCultureDMYOrder { get; set; }
  5. [DisplayFormat("dd/MM/yyyy")]
  6. public DateTime DateWithConstantDMYOrder { get; set; }
  7. [DisplayFormat("g")]
  8. public DateTime DateTimeToMinWithCultureDMYOrder { get; set; }
  9. [DisplayFormat("dd/MM/yyyy HH:mm")]
  10. public DateTime DateTimeToMinConstantDMYOrder { get; set; }
  11. [DisplayFormat("G")]
  12. public DateTime DateTimeToSecWithCultureDMYOrder { get; set; }
  13. [DisplayFormat("dd/MM/yyyy HH:mm:ss")]
  14. public DateTime DateTimeToSecWithConstantDMYOrder { get; set; }
  15. [DisplayFormat("s")]
  16. public DateTime SortableDateTime { get; set; }
  17. [DisplayFormat("u")]
  18. public DateTime ISO8601UTC { get; set; }
  19. [DisplayFormat("#,##0.00")]
  20. public Decimal ShowTwoZerosAfterDecimalWithGrouping { get; set; }
  21. [DisplayFormat("0.00")]
  22. public Decimal ShowTwoZerosAfterDecimalNoGrouping { get; set; }
  23. }

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.
  1. public class SomeForm
  2. {
  3. [Placeholder("Show this inside the editor when it is empty")]
  4. public string FieldWithPlaceHolder { get; set; }
  5. }

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.

  1. public class SomeForm
  2. {
  3. [Hint("Show this when my caption is hovered")]
  4. public string FieldWithHint { get; set; }
  5. }

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.

  1. public class SomeForm
  2. {
  3. [CssClass("extra-class")]
  4. public string FieldWithExtraClass { get; set; }
  5. }
  6. public class SomeColumn
  7. {
  8. [CssClass("extra-class")]
  9. public string CellWithExtraClass { get; set; }
  10. }

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.

  1. public class SomeColumn
  2. {
  3. [HeaderCssClass("extra-class")]
  4. public string FieldWithExtraHeaderClass { get; set; }
  5. }

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.

  1. public class SomeColumns
  2. {
  3. [Ignore]
  4. public string DontGenerateAColumnForMe { get; set; }
  5. }