将我的下拉列表更改为选定的下拉列表后,我无法获得验证消息。可以找到选择的插件here
Jquery code
$('#SelectedPropertyGroup').chosen();
UI Code
<div>
@Html.DropDownListFor(x => x.SelectedGroup, Model.Groups, "Select Group", new
{
@onchange = "javascript:ValidateApplicationSelection(this, 'Group');",
@placeholder = "Please select a product"
})
</div>
<div>
@Html.ValidationMessageFor(model => model.SelectedGroup, "", new { id = "valGroup" })
</div>
Model Code
[Required(ErrorMessage = "Select Group")]
[DisplayName("Group: ")]
public string SelectedGroup { get; set; }
答案 0 :(得分:3)
客户端验证默认忽略隐藏字段 - 选择隐藏&#34;真实&#34;当它应用它的魔力时选择元素。您可以像这样更改验证器默认值:
$.validator.setDefaults({ ignore: ":hidden:not(select)" });
这将设置验证器以忽略任何不选择元素的隐藏字段。
default for the ignore为":hidden"