public override async Task <IViewComponentResult> InvokeAsync(EntityFieldDefinition fieldDefinition, object value) { if (value is not IEnumerable <string> typedValue) { throw new ArgumentException($"ViewComponent parameter ${value} must be of type {nameof(IEnumerable<string>)}", nameof(value)); } var metadata = fieldDefinition.Using <CrudAdminEntityFieldFeature>(); if (!metadata.EditorProperties.TryGetValue("DataSource", out var dataSourceDefinition)) { throw new ArgumentNullException("DataSource"); } var dataSource = dataSourceFactory.Create(dataSourceDefinition); var data = await dataSourceReader.ReadFrom(dataSource); return(View(new MultiSelectFieldEditorViewModel { Id = fieldDefinition.Property.Name, FieldName = fieldDefinition.Property.Name, Label = fieldDefinition.DisplayName, Value = typedValue, Options = data.Select(x => new DropDownOptionViewModel { Value = x.Key, Label = x.Value, }), })); }
public override async Task <IViewComponentResult> InvokeAsync(EntityFieldDefinition fieldDefinition, object value) { var metadata = fieldDefinition.Using <CrudAdminEntityFieldFeature>(); if (!metadata.EditorProperties.TryGetValue("DataSource", out var dataSourceDefinition)) { throw new ArgumentNullException("DataSource"); } var dataSource = dataSourceFactory.Create(dataSourceDefinition); var data = await dataSourceReader.ReadFrom(dataSource); return(View(new DropDownFieldEditorViewModel { Id = fieldDefinition.Property.Name, FieldName = fieldDefinition.Property.Name, Label = fieldDefinition.DisplayName, Value = value?.ToString() ?? string.Empty, Options = data.Select(x => new DropDownOptionViewModel { Value = x.Key, Label = x.Value, }), })); }