在DropDownListFor验证与DataAnnotations工作 [英] Validation on DropDownListFor not working with DataAnnotations

查看:123
本文介绍了在DropDownListFor验证与DataAnnotations工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个下拉列表如下:

If I have a drop down list as follows

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

和在我的模型我使用DataAnnotations

and in my model I am using DataAnnotations

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

我怎样才能得到的消息出现在看法?
在调试我能看到的ModelState错误被填充,但在视图不显示的消息。
我没有问题,与其他控件显示错误消息(TextBoxFor)

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) %>

<%= Html.ValidationSummary() %>

这篇关于在DropDownListFor验证与DataAnnotations工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆