<%= Html.DropDownListFor...">

Validation on DropDownList Does not work with DataAnnotations

If I have a dropdown as follows

<div class="editor-label"> <%= Html.DropDownListFor(model => model.CardDetail.SelectedCardSchemeId, Model.CardDetail.CardSchemes, "Select")%> </div> 

and in my model I use DataAnnotations

 [Required(ErrorMessage = "* Required SelectedCardSchemeId Message")] public int SelectedCardSchemeId { get; set; } 

How can I get a message in a view? In debugging, I see that the ModelState error fills up, but the message does not appear in the view. I have no problem displaying an error message for other controls (TextBoxFor)

+1
source share
1 answer

Have you placed a confirmation mailbox?

 <%= Html.ValidationMessageFor(model => model.CardDetail.SelectedCardSchemeId) %> 

or

 <%= Html.ValidationSummary() %> 
+1
source

Source: https://habr.com/ru/post/899653/


All Articles