Ways to customize forms.
protected override IEnumerable<string> ShownFormControlNames {
// explicit fields
}
protected override IEnumerable<string> HiddenFormControlNames {
// hidden fields
}
someFormControl.IsReadOnly = true;
The GenerateFormControls
methods are the main way to customize the form fields generated for Create and Edit pages.
There are a few overload options:
// Basic signature
protected override IEnumerable<FormControlViewModel> GenerateFormControls(
TEntity entity,
EntityAction action,
IDictionary<string, string> entityDict)
// With option filters
protected override IEnumerable<FormControlViewModel> GenerateFormControls(
TEntity entity,
EntityAction action,
IDictionary<string, string> entityDict,
IDictionary<string, Expression<Func<object, bool>>> optionFilters)
// Async version
protected override async Task<IEnumerable<FormControlViewModel>> GenerateFormControlsAsync(...)
The methods return a collection of FormControlViewModel
representing each form control.
By default, it creates controls for:
- Primitive properties like strings, numbers.
- Navigation properties as dropdowns loaded from DbSets.
This requires no customization for basic cases.
You can customize the defaults like:
Hide fields
protected override IEnumerable<string> HiddenFormControlNames {
// fields to hide
}
Show only certain fields
protected override IEnumerable<string> ShownFormControlNames {
// fields to show
}
Make fields read-only
formControl.IsReadOnly = true;
To add completely custom controls, create and add FormControlViewModel
instances:
protected override IEnumerable<FormControlViewModel> GenerateFormControls()
{
// Create custom control
var ratingControl = new FormControlViewModel();
// Add to default fields
return base.GenerateFormControls().Concat(new[] { ratingControl });
}
For full control, override GenerateFormControls
and explicitly build the controls:
protected override IEnumerable<FormControlViewModel> GenerateFormControls()
{
return new FormControlViewModel[]
{
// Explicitly build controls
};
}
Let me know if you need any clarification or have additional questions!