Search K
Appearance
A CountryField
may be used to represent and store information related to countries in a resource. Its underlying type is always a string
.
Database storage
Please note that for I18N purposes, only the two-letter ISO code of a country will be stored in the database. For example, if you input 'Canada', the database will store its two-letter code 'CA'.
In our example application, we have a model class, which represents a company's real estate property. Each property lists the country where it's located in.
public class Property
{
[Key]
public int Id { get; init; }
[Required]
public string Country { get; set; }
}
In the resource we want to represent the country each property is located in with a CountryField
.
public override IList<IResourceFieldBuilder> Fields()
{
return
[
CountryField.Make("Country", nameof(Property.Country)),
];
}
A CountryField
displays the full country name.
In Create and Update views, a user will see a dropdown menu with a list of all available countries. Menu items will be shown based on the browser's preferred language and sorted alphabetically.
The default visibility values are as follows:
Resource View | Default |
---|---|
Index | visible |
Create | visible |
Update | visible |
Details | visible |
You can change the visibility of the field for each view. Please note, however, that fields should remain visible on Create pages if the field is required by the entity model and if no default value is set.
A CountryField
can be made sortable by chaining a call to Sortable()
after adding the field. Sorting will be performed in lexicographic order.
public override IList<IResourceFieldBuilder> Fields()
{
return
[
CountryField.Make("Country", nameof(Property.Country)).Sortable(),
];
}