[英]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.