Validation on DropDownListFor not working with DataAnnotations
If I have a drop down list as follows
<div class="editor-label">
<%= Html.DropDownListFor(model => model.CardDetail.SelectedCardScheme开发者_如何学编程Id,
Model.CardDetail.CardSchemes, "Select")%>
</div>
and in my model I am using DataAnnotations
[Required(ErrorMessage = "* Required SelectedCardSchemeId Message")]
public int SelectedCardSchemeId { get; set; }
How can I get the message to appear in the view? In debug I can see the ModelState error is populated, but the message is not displayed on the view. I do not have issues with displaying error message for other controls (TextBoxFor)
Did you put a validation message placeholder?
<%= Html.ValidationMessageFor(model => model.CardDetail.SelectedCardSchemeId) %>
or:
<%= Html.ValidationSummary() %>
精彩评论