protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) { if (modelType == typeof(ColumnValidation)) { var validationType = (ValidationType)bindingContext.ValueProvider.GetValue(bindingContext.ModelName + ".ValidationType").ConvertTo(typeof(Kooboo.CMS.Form.ValidationType)); object model = null; switch (validationType) { case ValidationType.Required: model = new RequiredValidation(); break; case ValidationType.StringLength: model = new StringLengthValidation(); break; case ValidationType.Range: model = new RangeValidation(); break; case ValidationType.Regex: model = new RegexValidation(); break; } bindingContext.ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(() => model, model.GetType()); return(model); } return(base.CreateModel(controllerContext, bindingContext, modelType)); }
protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) { if (modelType == typeof(ColumnValidation)) { var validationType = (ValidationType)bindingContext.ValueProvider.GetValue(bindingContext.ModelName + ".ValidationType").ConvertTo(typeof(Kooboo.CMS.Form.ValidationType)); object model = null; switch (validationType) { case ValidationType.Required: model = new RequiredValidation(); break; case ValidationType.StringLength: model = new StringLengthValidation(); break; case ValidationType.Range: model = new RangeValidation(); break; case ValidationType.Regex: model = new RegexValidation(); break; } bindingContext.ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(() => model, model.GetType()); return model; } return base.CreateModel(controllerContext, bindingContext, modelType); }