绑定到 Html.DropdownListfor 的 MVC3 模型属性在通过 Jquery 选择下拉列表时未更新

发布于 2024-12-06 05:25:20 字数 355 浏览 4 评论 0原文

我有一个带有 ASPX 视图引擎的 MVC3 应用程序。我的页面有一个下拉列表,是通过

Html.DropdownListFor(m=>m.EmpId,(selectlist)Model.EmpDetails).

我更新此下拉列表而创建的,在这种情况下,它只有一个项目,并通过 Jquery 禁用该项目。现在,当我转到表单发布时,我的模型的 'EmpId' 属性不会使用下拉列表中所选项目的相应值进行更新。我怀疑,由于下拉列表不是手动选择的(由 Jquery 更新),因此我在模型中没有获取 'EmpId' 。有办法解决这个问题吗?

就此而言, 沙拉瓦南

I have a MVC3 application with ASPX view engine. My page is having a dropdownlist created by

Html.DropdownListFor(m=>m.EmpId,(selectlist)Model.EmpDetails).

I update this dropdown on a situation where it would have only one item and make that disabled, by Jquery. Now when I go to form post, my model's 'EmpId' property is not updated with the corresponding value of its selected item in dropdown list. I suspect, since the dropdownlist is not manually selected (updated by Jquery), I'm not getting 'EmpId' in my model. Is there a way to overcome this issue?

With regards,
Saravanan

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

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

发布评论

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

评论(2

谁对谁错谁最难过 2024-12-13 05:25:20

禁用的表单字段不会发布到服务器。如果你想阻止用户手动更改它,你可以将其设置为只读

Disabled form fields are not posted to the server. you can make it readonly if u want to stop users from manually changing it

我三岁 2024-12-13 05:25:20

disabled 表单字段不参与发送到服务器的表单值。这就是为什么您的 EmpId 没有填充在服务器上 - 它在那里不存在。使 readonly 而不是 disabled 可能会对您有所帮助。如果您在服务器上需要表单字段,请不要禁用它。

disabled form fields do not participate in form values sent to server. That is why your EmpId is not populated on server - it does not exist there. Making that readonly instead of disabled may help you. Do not disable form field if you need it on server.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文