asp.net mvc - StringLength/Minlength validation doesn't prevent user from posting the form with no value -


i have following property on viewmodel

[stringlength(20, minimumlength = 1, errormessageresourcename = "error_stringlength", errormessageresourcetype = typeof(global))] public string leaguename { get; set; } 

if string ends being larger 20 characters validation fire , not allow user post form. however, if field blank, means leaguename property has length of less 1 allow user post form.

i know resolved using required attribute, why validation not working expected in scenario?

it design.

this validation logic stringlength:

public override bool isvalid(object value) {   this.ensurelegallengths();   int num = value == null ? 0 : ((string) value).length;   if (value == null)     return true;   if (num >= this.minimumlength)     return num <= this.maximumlength;   else     return false; } 

as can see, when string null stringlength returns true.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -