Exemplo n.º 1
0
        public Task BindModelAsync(ModelBindingContext bindingContext)
        {
            var model    = bindingContext.ModelName;
            var hasValue = false;

            if (!bindingContext.TryGetStringArray($"{model}", ref hasValue, out var value))
            {
                return(Task.CompletedTask);
            }

            if (!bindingContext.TryGetStringArray($"{model}.fields", ref hasValue, out var rec))
            {
                return(Task.CompletedTask);
            }

            if (!bindingContext.TryGetStringArray($"{model}.values", ref hasValue, out var tup))
            {
                return(Task.CompletedTask);
            }

            if (!hasValue)
            {
                bindingContext.Result = ModelBindingResult.Success(null);
                return(Task.CompletedTask);
            }

            bindingContext.Result = ModelBindingResult.Success(new SelectParameter
            {
                Fields = value ?? rec,
                Values = tup
            });

            return(Task.CompletedTask);
        }