0
I have a IEnumerable<long> selectedItems
he is to display a select
to select multiple values, I want to validate this IEnumerable
using the DataAnnotations
to check if it is empty because it needs at least to have a selected value. I am trying to use the Required
but it’s not working. How can I do it ?
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>
needed to remove the
@multiple = true
tbm in HTML. But now it worked blah. thank you.– FernandoPaiva
@Fernandopaiva I used with Multiple and was also right, but, all right that matters that your doubt has been solved! and did the editing to stay the way it was the solution.
– novic