[英]Required Field Validator not working for JQuery chosen drop down list
I am using JQuery Choosen for my DropDownList but the required validator for that dropdown is not working . 我正在使用JQuery Choosen作为我的DropDownList,但该下拉列表所需的验证器不起作用。 Following is my code .Please guide where i am wrong.
以下是我的代码。请指导我错了。
Chosen plugin included in the form 选择插件包含在表单中
$(".chosen-select").chosen();
DropDownList code 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>
And Model for the DropDownList 和DropDownList的模型
[Required(ErrorMessage = "*")]
[Display(Name = "Department Name")]
public int DepartmentId { get; set; }
jQuery Chosen updates the html by making the original select hidden (style="Display:none"). jQuery Chosen通过使原始选择隐藏来更新html(style =“Display:none”)。 By default jquery.validate (1.9.0) ignores hidden elements.
默认情况下,jquery.validate(1.9.0)忽略隐藏的元素。 You can override the default using
您可以使用覆盖默认值
$.validator.setDefaults({
ignore: []
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.