I am using MVC3, EF Model first.
I have a form with two DropDownList that gets disabled depending on what value the user choose on another dropdownlist, i’ve used Jquery for this here is the code:
$(function () {
$('#SubjectTypeName').change(function () {
var value = $(this).val();
if (value == '2') {
$('#TeamName, #ConsultantName').removeAttr('disabled');
} else if (value == '3') {
$('#TeamName').attr('disabled', 'disabled');
$('#ConsultantName').attr('disabled', 'disabled');
} else if (value == '4') {
$('#TeamName').attr('disabled', 'disabled');
$('#ConsultantName').attr('disabled', 'disabled');
}
$(".questionsForSubjectType").hide();
$("#questionsForSubjectType_" + value).show();
});
})
But when the DropDownList is disabled and I click on next page, the disabled DropDownLists gets validated by MVC standard Jquery validation that I have. I’ve done the validation by declaring [Required] on my properties in my ViewModel for this validation. How can I prevent the validation on my disabled DropDownlists but still make sure the DropDownLists gets validated if they are enabled
Thanks in Advance!
Is the
[Required]attribute on the field the dropdown is for set? Perhaps removing this could help if that is the case.You could also consider populating partial views based on user input.