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"
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.