IEnumerable<long> selectedItems
using select
to check if it is empty because it needs to at least have a selected value. I have a IEnumerable
it's to display a DataAnnotations
to select multiple values. I'm trying to use Required
but it's not working. How can I do this?
I'm trying like this.
Model
public class EmpresaModel{
[Required(ErrorMessage = "Selecione ao menos uma forma de pagamento disponível")]
public IEnumerable<long> selectedItems { get; set; }
}
HTML
<div class="form-group">
<label for="@Html.IdFor(model => model.selectedItems)" class="cols-sm-2 control-label">Formas de pagamento disponíveis <img src="~/Imagens/required.png" height="6" width="6"></label>
@Html.ListBoxFor(model => model.selectedItems, Model.formasPagto, new { Class = "form-control", placeholder = "Selecione as formas de pagamento disponíveis", @multiple = true})
@Html.ValidationMessageFor(model => model.formasPagto)
</div>