'Custom Validation doesn't show the message when the List is empty in client side validation
I have List in my model which I want to have data Annotation for that
[ValidListNotEmpty(ErrorMessage = "List could not be Empty")]
public List<Features> Features { get; set; }
I have programmed an Custome DataAnnotation
public class ValidListNotEmptyAttribute : ValidationAttribute
{
private readonly int _minElements;
public ValidListNotEmptyAttribute()
{
}
public override bool IsValid(object value)
{
var list = value as IList;
if (list != null)
{
return list.Count >= 0;
}
return false;
}
}
I have used these tag in View to check and show the message
<select class="form-control" id="Category" asp-for="Features"></select>
<span asp-validation-for="Features" class="text-danger"></span>
but the Custome Validation doesn't show no error message when the list is empty in client side validation, it should should goes to server to be validated how can I make the validation to show error message when the List is empty on client side?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
