ASP.NET MVC 隐藏字段无法 POSTing

发布于 2024-08-23 11:55:14 字数 1248 浏览 4 评论 0原文

使用 jquery 自动完成功能,我有一个隐藏的输入字段来存储 ID,因为名称会在选择时输入到自动完成字段中。

像这样:

        $("#Clients").result(function (event, data, formatted) {
            if (data) {
                $("#ClientID").val(data["client_ClientNumber"]);
                if (data["ClientName"] && data["client_address1"] && data["client_postcode"] && data["client_postname"]) {
                    $("#ClientDetails").html(
                    "<li class=\"clientNumber\">Client ID: " + data["client_ClientNumber"] + "</li>" +
                    "<li>" + data["ClientName"] + "</li>" +
                    "<li>" + data["client_address1"] + "</li>" +
                    "<li>" + data["client_postcode"] + data["client_postname"] + "</li>"
                    );
                }
}

这是我的 HTML:

    <div id="ClientSelectionPlaceholder">
        <h3>Client</h3>
        <%=Html.TextBox("Clients", null, new { @class = "clientsDropDown" })%>
        <%=Html.Hidden("ClientID", null, new { disabled = true}) %>
    </div>

问题是这个隐藏的 ClientID 字段不会回发,也不会使用 jquery.serialize() 进行序列化。它总是失踪。但据我所知,我的代码看起来不错。

With jquery autocomplete I have a hidden input field to store ID because the name gets inputted into the autocomplete field on select.

Like this:

        $("#Clients").result(function (event, data, formatted) {
            if (data) {
                $("#ClientID").val(data["client_ClientNumber"]);
                if (data["ClientName"] && data["client_address1"] && data["client_postcode"] && data["client_postname"]) {
                    $("#ClientDetails").html(
                    "<li class=\"clientNumber\">Client ID: " + data["client_ClientNumber"] + "</li>" +
                    "<li>" + data["ClientName"] + "</li>" +
                    "<li>" + data["client_address1"] + "</li>" +
                    "<li>" + data["client_postcode"] + data["client_postname"] + "</li>"
                    );
                }
}

This is my HTML:

    <div id="ClientSelectionPlaceholder">
        <h3>Client</h3>
        <%=Html.TextBox("Clients", null, new { @class = "clientsDropDown" })%>
        <%=Html.Hidden("ClientID", null, new { disabled = true}) %>
    </div>

The problem is that this hidden ClientID field is not posting back nor it does serialize with jquery.serialize(). It is always missing. But as far as I can tell my code looks fine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

手长情犹 2024-08-30 11:55:14

为什么要禁用隐藏字段?不。

Why have you disabled the hidden field? Don't.

雪化雨蝶 2024-08-30 11:55:14

这是因为该字段被禁用。

...new { disabled = true}...

It is because the field is disabled.

...new { disabled = true}...
圈圈圆圆圈圈 2024-08-30 11:55:14

当您将禁用属性设置为输入元素时,其值将NOT发布:

<%=Html.Hidden("ClientID", null, new { disabled = true}) %>

When you set the disabled attribute to an input element it's value is NOT posted:

<%=Html.Hidden("ClientID", null, new { disabled = true}) %>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文