Hidden fields are shown on validation ASP MVC
I am creating a small application on MVC and created a script based on the
index values of dropdown list. The Script hides/shows div based on the
user selection of dropdown list items. it works fine but when the
validation errors occurs, MVC shows all the hidden fields which were hided
by the script. Hidden fields should remain hidden regardless of
validation. i have following codes View @Html.LabelFor(model =>
model.EligPeriod) @Html.EditorFor(model => model.EligPeriod)
@Html.ValidationMessageFor(model => model.EligPeriod)
</div>
JavaScript $("#EmploymentTypeName").change(function () {
var val = $("#EmploymentTypeName").prop("selectedIndex");
if (val == 3) {
$("#eligibleperiod").hide();
}
else {
$("#eligibleperiod").show();
}
//to remove all validation parameter e.g required /range when the field is
hidden
$.validator.setDefaults({
ignore: ':hidden, [readonly=readonly]'
});
});
No comments:
Post a Comment