gpt4 book ai didi

javascript - 将 jQuery 禁用输入值发送到 MVC Controller

转载 作者:太空宇宙 更新时间:2023-11-04 15:34:03 24 4
gpt4 key购买 nike

我确实有一个 MVC ASP.NET 表单,需要来自用户的数据,特别是用户有九个[必需]文本框来填充应有的信息,并且大多数时候其中八个文本框的信息是相同的所以我让用户一次填写表单的所有字段,然后按一个重复按钮,该按钮允许用户仅指定一个文本框的数据,其他八个文本框将填充之前指定的数据......但是不允许用户更改此重复信息,因此我使用 jQuery

$("#idDireccion").attr("disabled", "disabled");
$("#idEvento").attr("disabled", "disabled");
$("#ddDepartamentos").attr("disabled", "disabled");
$("#ddMunicipios").attr("disabled", "disabled");
$("#idLugar").attr("disabled", "disabled");
$("#datepicker").attr("disabled", "disabled");
$("#idHoras").attr("disabled", "disabled");
$("#idPrecio").attr("disabled", "disabled");

并通过ViewBag指定重复值

@Html.EditorFor(model => model.lugarEvento, new { htmlAttributes = new { @class = "form-control left-border-none", @title = "especifique lugar en que impartirá el evento", @id = "idLugar", @Value = ViewBag.lugarEvento } })

我对八个文本框执行此操作,它显示信息并且不允许用户更改该信息,但是当用户将表单提交到处理数据库操作的 Controller 时,不会从重复的内容中接收任何内容info(属于 ViewModel 的一部分)所有值均为 null。

我的问题是我必须做什么才能不让用户修改重复的信息并仍然在我的 Controller 中接收重复的信息。

最佳答案

不要使用禁用属性,而应使用只读属性。这会将值发送到 Controller 。

        $("#idDireccion").attr('readonly', true);
$("#idEvento").attr('readonly', true);
$("#ddDepartamentos").attr('readonly', true);
$("#ddMunicipios").attr('readonly', true);
$("#idLugar").attr('readonly', true);
$("#datepicker").attr('readonly', true);
$("#idHoras").attr('readonly', true);
$("#idPrecio").attr('readonly', true);

关于javascript - 将 jQuery 禁用输入值发送到 MVC Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44553897/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com