[英]harvest chosen plugin fails to show validation messages for asp.net mvc dropdown list
I am unable to get validation messages after changing my dropdownlist to chosen dropdown list. 将我的下拉列表更改为选定的下拉列表后,我无法获得验证消息。 Chosen plugin can be found 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; }
The client side validation ignores hidden fields by default -- Chosen hides the "real" select element when it applies it's magic. 客户端验证默认忽略隐藏字段 - 选择隐藏“真实”选择元素时应用它的魔力。 You can change the validator defaults like so:
您可以更改验证器默认值,如下所示:
$.validator.setDefaults({ ignore: ":hidden:not(select)" });
This will set the validator to ignore any hidden fields that aren't select elements. 这将设置验证器以忽略任何不是选择元素的隐藏字段。
The default for the ignore is ":hidden"
忽略的默认值是
":hidden"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.