我正在尝试验证IEnumerable<long> selectedItems
如果不为空或空但我不能这样做,它需要选择一个或多个选项,因为它是一个多选项。我怎么能这样做?
尝试。
模型
public class EmpresaModel{
public IEnumerable<SelectListItem> formasPagto { get; set; }
[Required(ErrorMessage = "Choose one or more options")]
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>