繁体   English   中英

必需的字段验证器不适用于JQuery选择的下拉列表

[英]Required Field Validator not working for JQuery chosen drop down list

我正在使用JQuery Choosen作为我的DropDownList,但该下拉列表所需的验证器不起作用。 以下是我的代码。请指导我错了。

选择插件包含在表单中

 $(".chosen-select").chosen();

DropDownList代码

<li>
    @Html.LabelFor(m => m.DepartmentId)
    @Html.DropDownListFor(x => x.DepartmentId, (ViewBag.DepartmentsList) as IEnumerable<SelectListItem>, "-- Select an Option --",new { @class = "chosen-select", @style = "width:312px; height:31px;" })
    @Html.ValidationMessageFor(m => m.DepartmentId)
</li>

和DropDownList的模型

[Required(ErrorMessage = "*")]
[Display(Name = "Department Name")]
public int DepartmentId { get; set; }

jQuery Chosen通过使原始选择隐藏来更新html(style =“Display:none”)。 默认情况下,jquery.validate(1.9.0)忽略隐藏的元素。 您可以使用覆盖默认值

$.validator.setDefaults({ 
  ignore: []
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM