public void OnMetadataCreated(System.Web.ModelBinding.ModelMetadata metadata) { var list = Context.Items["Scripts"] as IList <string> ?? new List <string>(); _count = list.Count; metadata.TemplateHint = templateHint; metadata.AdditionalValues[templateHint] = Id; list.Add(string.Format(ScriptText, Id, Mask)); Context.Items["Scripts"] = list; }
/// <summary> /// Revalidates the model passed as the first parameter. /// </summary> /// <param name="model">The model instance you wish to validate.</param> /// <returns></returns> protected internal bool TryValidateModel(object model) { if (model == null) { throw new ArgumentNullException("model"); } System.Web.ModelBinding.ModelMetadata metadata = ModelMetadataProviders.Current.GetMetadataForType(() => model, model.GetType()); var t = new ModelBindingExecutionContext(new HttpContextWrapper(HttpContext.Current), new System.Web.ModelBinding.ModelStateDictionary()); foreach (ModelValidationResult validationResult in ModelValidator.GetModelValidator(metadata, t).Validate(null)) { ModelState.AddModelError(validationResult.MemberName, validationResult.Message); } return ModelState.IsValid; }
public MinLengthAttributeAdapter(ModelMetadata metadata, ModelBindingExecutionContext context, MinLengthAttribute attribute) : base(metadata, context, attribute) { }
internal static ModelValidator Create(ModelMetadata metadata, ModelBindingExecutionContext context, ValidationAttribute attribute) { return(new DataAnnotationsModelValidator(metadata, context, attribute)); }
public IEnumerable <ModelValidator> GetValidators(ModelMetadata metadata, ModelBindingExecutionContext context) { return(this.SelectMany(provider => provider.GetValidators(metadata, context))); }