Validation on DropDownListFor not working with DataAnnotations

Posted by Noel on Stack Overflow See other posts from Stack Overflow or by Noel
Published on 2010-03-31T07:37:39Z Indexed on 2010/03/31 7:43 UTC
Read the original article Hit count: 734

Filed under:

If I have a drop down list as follows

<div class="editor-label">
 <%= Html.DropDownListFor(model => model.CardDetail.SelectedCardSchemeId,
  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)

© Stack Overflow or respective owner

Related posts about asp.net-mvc