示例#1
0
        private ComplexModelDto CreateAndPopulateDto(HttpActionContext actionContext, ModelBindingContext bindingContext, IEnumerable <ModelMetadata> propertyMetadatas)
        {
            ModelMetadataProvider metadataProvider = MetadataProvider ?? actionContext.GetMetadataProvider();

            // create a DTO and call into the DTO binder
            ComplexModelDto     originalDto       = new ComplexModelDto(bindingContext.ModelMetadata, propertyMetadatas);
            ModelBindingContext dtoBindingContext = new ModelBindingContext(bindingContext)
            {
                ModelMetadata = metadataProvider.GetMetadataForType(() => originalDto, typeof(ComplexModelDto)),
                ModelName     = bindingContext.ModelName
            };

            IModelBinder dtoBinder = actionContext.GetBinder(dtoBindingContext);

            dtoBinder.BindModel(actionContext, dtoBindingContext);
            return((ComplexModelDto)dtoBindingContext.Model);
        }