如果有人輸入一個值,但如果他們沒有輸入任何內容,我需要控制一個最小長度的字段,我不希望表單告訴他們有一個最小值。指定最小長度,如果字段有數據
這是我有:
[Required]
[StringLength(15, ErrorMessage = "Please supply at least {2} characters.", MinimumLength = 3)]
[Display(Name = "Last name on account or first part of the company's name")]
public string LastName { get; set; }
我只需要爲它允許空格也或者,如果輸入的數據,要求它的3個字符..
任何建議一分鐘?
** [你可以在這裏查一下。希望你會覺得它有用。](http://stackoverflow.com/questions/18276853/string-minlength-and-maxlength-validation-dont-work-asp-net-mvc/18276949#18276949)** –
Similar: http://stackoverflow.com/questions/5487094/asp-net-mvc3-model-validation-string-is-null-or-if-not-has-min-length-of-x – SepehrM