I am working show the drop down values on selection of a check box. But with the below code, all different items that are present in the drop down coming directly.
Somehow the @Html.DropDownListFor is not working inside select tag, can anyone please help me to fix it?
Note: Checkbox toggle working perfectly.
Thank you,
<input type="checkbox" />
<p>check this box to escalate</p>
<select disabled="disabled">
@Html.DropDownListFor(
model => model.EscalationQueue,
new SelectList(Extensions.EscalationQueue, Model.EscalationQueue),
new { @class = "escalation-queue", name = Model.EscalationQueue }
)
</select>
var dropdownToggle = function () {
$("input:checkbox").change(function () {
if ($("input:checkbox").is(":checked")) {
$("select").removeAttr("disabled");
}
else {
$("select").attr("disabled", "disabled");
}
});
}
$(document).ready(function () {
dropdownToggle();
});
Output:


You dont need the <select> tag, the HtmlHelper DropDownListFor will render that for you.
If you want to initialize the dropdown as disabled set the html attribute as you did for declaring a cssclass...
<input type="checkbox" />
<p>check this box to escalate</p>
@Html.DropDownListFor(
model => model.EscalationQueue,
new SelectList(Extensions.EscalationQueue, Model.EscalationQueue),
new { @class = "escalation-queue",
name = Model.EscalationQueue,
disabled= "disabled"
}
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With