public void Validate(ActionContext actionContext, ValidationStateDictionary validationState, string prefix, object model)
        {
            var requiredErrorsNotHandledByFv = RemoveImplicitRequiredErrors(actionContext);

            // Apply any customizations made with the CustomizeValidatorAttribute
            var metadata = model == null ? null : _modelMetadataProvider.GetMetadataForType(model.GetType());

            if (model != null)
            {
                var customizations = GetCustomizations(actionContext, model.GetType(), prefix);
                actionContext.HttpContext.Items["_FV_Customizations"] = Tuple.Create(model, customizations);
            }

            // Setting as to whether we should run only FV or FV + the other validator providers
            var validatorProvider = _runMvcValidation ? _compositeProvider : _fvProvider;

            var visitor = new ValidationVisitorFork(
                actionContext,
                validatorProvider,
                _validatorCache,
                _modelMetadataProvider,
                validationState);

            visitor.Validate(metadata, prefix, model);

            // Re-add errors that we took out if FV didn't add a key.
            ReApplyImplicitRequiredErrorsNotHandledByFV(requiredErrorsNotHandledByFv);

            // Remove duplicates. This can happen if someone has implicit child validation turned on and also adds an explicit child validator.
            RemoveDuplicateModelstateEntries(actionContext);
        }
예제 #2
0
            public StateManager(ValidationVisitorFork visitor, object newModel)
            {
                _visitor  = visitor;
                _newModel = newModel;

                _container = _visitor.Container;
                _key       = _visitor.Key;
                _metadata  = _visitor.Metadata;
                _model     = _visitor.Model;
                _strategy  = _visitor.Strategy;
            }
예제 #3
0
            public static StateManager Recurse(
                ValidationVisitorFork visitor,
                string key,
                ModelMetadata metadata,
                object model,
                IValidationStrategy strategy)
            {
                var recursifier = new StateManager(visitor, model);

                visitor.Container = visitor.Model;
                visitor.Key       = key;
                visitor.Metadata  = metadata;
                visitor.Model     = model;
                visitor.Strategy  = strategy;

                return(recursifier);
            }