简体   繁体   中英

How to submit a disabled drop down list in ASP.NET MVC?

I'm displaying a drop down menu using the following syntax:

@Html.DropDownListFor(model => model.Country, new SelectList(Model.CountryOptions, "Key", "Value"))

I have a Jquery statement which disabled the dd based on a check box:

$(document).ready(function () {
    $("#lockRecord").click(function () {
        if ($(this).attr('checked')) {
            $("#Country").attr('disabled', true);
        } else {
            $("#Country").attr("disabled", false);
        }
    })
});

However, when it's submitted, the value returns as null. Have tried readonly, but it doesn't work on drop down lists.

Any suggestions?

Take the value and submit it in a hidden field when the drop down is disabled. Of course, your server code will need to be modified to take that value, but that's a small price to pay.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM