aspnetmvc-402285-common-features-data-annotation-attributes.md
DevExpress ASP.NET MVC components support data annotation attributes. You can apply these attributes to classes to specify validation rules and data display mode, set relationships between classes, etc.
Model:
public class RegistrationData {
[Required(ErrorMessage = "*")]
[DisplayFormat(NullDisplayText = "First Name")]
[Display(Name = "Caption")]
public string FirstName { get; set; }
[Required(ErrorMessage = "*")]
[DisplayFormat(NullDisplayText = "Last Name")]
public string LastName { get; set; }
...
}
View:
@Html.DevExpress().FormLayout(settings => {
...
settings.Items.AddGroupItem(m => m.RegistrationData, g => {
...
g.Items.Add(m => m.RegistrationData.FirstName, i => {
i.Caption = "Name";
i.NestedExtension().TextBox(s => {
AssignTextBoxSettings(s);
s.Properties.ValidationSettings.ErrorText = "*";
});
});
g.Items.Add(m => m.RegistrationData.LastName, i => {
i.Caption = "Last Name";
i.NestedExtension().TextBox(s => {
AssignTextBoxSettings(s);
s.Properties.ValidationSettings.ErrorText = "*";
});
});
...
});
}).GetHtml()
See also : Binding Data Editors to Data
Common data attributes supported by DevExpress data componenets are as follows.
DisplayAttribute - Specifies localizable strings for classes and members.
DisplayColumnAttribute - Specifies the column that a component (such as GridView) displays in a table as a foreign-key column.
CheckBoxValuesAttribute - Specifies the check box value.
DisplayFormatAttribute - Specifies a data field’s display format.
EditableAttribute - Specifies whether you can edit a data field.
KeyAttribute - Indicates that a property or a field is a key.
MaxLengthAttribute - Specifies a property value’s maximum length.
MinLengthAttribute - Specifies a property value’s minimum length.
PhoneAttribute - Specifies that a data field value is a phone number.
RegularExpressionAttribute - Specifies that a data field value should match the specified regular expression.
UIHintAttribute - Specifies a template or user control to display a data field.
BindableTypeAttribute - Specifies whether the data type is bindable.
DataTypeAttribute - Specifies the type of a data field’s value.
EnumDataAttribute - Replaces numeric enumerator values with corresponding declarations.
MetadataTypeAttribute - Gets data annotation attributes from the specified class.
ScaffoldColumnAttribute - Specifies whether a class or data column is hidden.
ScaffoldTableAttribute - Specifies whether a class or data table is hidden.
TimestampAttribute - Specifies a column’s data type as a row version.
CompareAttribute - Compares an editor’s value with another property.
ConcurrencyCheck - Checks a property for optimistic concurrency.
HtmlSettingsAttribute - Specifies HTML edit settings for the data field value.
CreditCardAttribute - Validates a field value as a credit card number.
CheckBoxRequiredAttribute - Specifies that a check box is required.
CustomValidationAttribute - Specifies a custom validation method.
EmailAddressAttribute - Validates a field value as an email address.
FileExtensionsAttribute - Validates file name extensions.
DateRangeAttribute - Specifies date range settings.
MaskAttribute - Specifies mask settings.
RangeAttribute - Specifies numeric range constraints for the data field value.
StringLengthAttribute - Specifies the maximum and minimum length of characters allowed in a data field.
RequiredAttribute - Specifies that a data field value is required.
UrlAttribute - Validates a URL.