[MinLength(6)]
public string Foo { get; set; }
If the value for this field is an empty string the web api model validator adds an error: "Foo must be a string or array type with a minimum length of 6"
Shouldn't an empty string be treated the same as null?
If I wanted a validation error for empty string I would add a [Required] validator.
Comments: It's not a Web API thing. MinLength belongs to System.ComponentModel.DataAnnotations.dll and it has the following implementation: public override bool IsValid(object value) { this.EnsureLegalLengths(); if (value == null) { return true; } string text = value as string; int length; if (text != null) { length = text.Length; } else { length = ((Array)value).Length; } return length >= this.Length; } If it doesn't work for you, just create a new one. It is fairly simple.
public string Foo { get; set; }
If the value for this field is an empty string the web api model validator adds an error: "Foo must be a string or array type with a minimum length of 6"
Shouldn't an empty string be treated the same as null?
If I wanted a validation error for empty string I would add a [Required] validator.
Comments: It's not a Web API thing. MinLength belongs to System.ComponentModel.DataAnnotations.dll and it has the following implementation: public override bool IsValid(object value) { this.EnsureLegalLengths(); if (value == null) { return true; } string text = value as string; int length; if (text != null) { length = text.Length; } else { length = ((Array)value).Length; } return length >= this.Length; } If it doesn't work for you, just create a new one. It is fairly simple.