ASP.NET MVC 隐藏字段无法 POSTing
使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么要禁用隐藏字段?不。
Why have you disabled the hidden field? Don't.
这是因为该字段被禁用。
It is because the field is disabled.
当您将禁用属性设置为输入元素时,其值将NOT发布:
When you set the disabled attribute to an input element it's value is NOT posted: