绑定到 Html.DropdownListfor 的 MVC3 模型属性在通过 Jquery 选择下拉列表时未更新
我有一个带有 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
禁用的表单字段不会发布到服务器。如果你想阻止用户手动更改它,你可以将其设置为只读
Disabled form fields are not posted to the server. you can make it readonly if u want to stop users from manually changing it
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 thatreadonly
instead ofdisabled
may help you. Do not disable form field if you need it on server.