简体   繁体   English

如何在ASP.NET MVC中提交禁用的下拉列表?

[英]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: 我有一个Jquery语句,它根据一个复选框禁用了dd:

$(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. 但是,在提交时,该值将返回null。 Have tried readonly, but it doesn't work on drop down lists. 尝试过readonly,但它不适用于下拉列表。

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. 当然,您的服务器代码需要修改才能获得该值,但这是一个很小的代价。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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