public async Task BindModelAsync(ModelBindingContext bindingContext)
    {
        if (bindingContext == null)
        {
            throw new ArgumentNullException(nameof(bindingContext));
        }

        _logger.AttemptingToBindModel(bindingContext);

        object model;
        var    request = bindingContext.HttpContext.Request;

        if (request.HasFormContentType)
        {
            var form = await request.ReadFormAsync();

            model = form;
        }
        else
        {
            _logger.CannotBindToFilesCollectionDueToUnsupportedContentType(bindingContext);
            model = new EmptyFormCollection();
        }

        bindingContext.Result = ModelBindingResult.Success(model);
        _logger.DoneAttemptingToBindModel(bindingContext);
    }
Exemplo n.º 2
0
        private async Task <ModelBindingResult> BindModelCoreAsync(ModelBindingContext bindingContext)
        {
            object model;
            var    request = bindingContext.OperationBindingContext.HttpContext.Request;

            if (request.HasFormContentType)
            {
                var form = await request.ReadFormAsync();

                model = form;
            }
            else
            {
                model = new EmptyFormCollection();
            }

            bindingContext.ValidationState.Add(model, new ValidationStateEntry()
            {
                SuppressValidation = true
            });
            return(ModelBindingResult.Success(bindingContext.ModelName, model));
        }
        /// <inheritdoc />
        public async Task BindModelAsync(ModelBindingContext bindingContext)
        {
            if (bindingContext == null)
            {
                throw new ArgumentNullException(nameof(bindingContext));
            }

            object model;
            var    request = bindingContext.HttpContext.Request;

            if (request.HasFormContentType)
            {
                var form = await request.ReadFormAsync();

                model = form;
            }
            else
            {
                model = new EmptyFormCollection();
            }

            bindingContext.Result = ModelBindingResult.Success(model);
        }