Hi
MVC 5
@Html.DropDownList("DDCA", ViewData["DDCA"] as List
i am binding values like this after genrate otp i want to disable this drop down while submit i am using
@disable="disable" but submition time dtop down value comes null i remove disable drop dwon value i will get but i want to disable and get that value while submission

Tahir AnsariRank #366 · 6.8K reputationPosted Jan 23, 2024, 9:20 AM EST
If you want to disable the dropdown during form submission but still receive its selected value, you should use the
disabledattribute in the HTML and manage the disabled state using JavaScript or Razor syntax. The@disable="disable"you mentioned seems like a typo; the correct attribute isdisabled.@Html.DropDownList("DDCA", ViewData["DDCA"] as List, "-- Select --", new { @class = "form-control text-center", id = "myDropdown" }) // JavaScript to disable the dropdown on form submission document.getElementById('myDropdown').disabled = true; // You can use the onsubmit event of your form to enable the dropdown before submission document.getElementById('yourFormId').onsubmit = function () { document.getElementById('myDropdown').disabled = false; };@Html.DropDownList("DDCA", ViewData["DDCA"] as List, "-- Select --", new { @class = "form-control text-center", id = "myDropdown" }) // jQuery to disable the dropdown on form submission $(document).ready(function () { $('#myDropdown').prop('disabled', true); // You can use the submit event of your form to enable the dropdown before submission $('#yourFormId').submit(function () { $('#myDropdown').prop('disabled', false); }); });Alpesh ManiyaRank #832 · 2.7K reputationPosted Jan 23, 2024, 9:27 AM EST
You may try with below steps
Add a hidden field to store the selected dropdown value:
Use JavaScript to disable the dropdown and update the hidden field during form submission:
function submitForm() { var dropdown = document.getElementById("DDCA"); var hiddenField = document.getElementById("DDCA_SelectedValue"); dropdown.disabled = true; hiddenField.value = dropdown.value; document.forms["yourFormName"].submit(); }Modify the submit button to call the JavaScript function:
This approach ensures that the dropdown is visually disabled for user interaction, but its selected value is still included in the form submission.