Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Commented Issue: MinLength validator fails on empty string [375]

$
0
0
[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.

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>