I am using JQuery Choosen for my DropDownList but the required validator for that dropdown is not working . Following is my code .Please guide where i am wrong.
Chosen plugin included in the form
$(".chosen-select").chosen();
DropDownList code
<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
[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"). By default jquery.validate (1.9.0) ignores hidden elements. You can override the default using
$.validator.setDefaults({
ignore: []
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.