MVC - 当模型值为空时,DropDownList 选择错误选项

发布于 2024-11-19 14:50:15 字数 272 浏览 6 评论 0原文

我的表单中有两个 DropDownList,都显示区域列表。第一个是必需的,第二个不是,在数据库中存储为 null。 当我打开页面进行编辑时,第一个下拉列表是 ie。区域2,第二个为空,第一个选项“<未指定>”应在第二个下拉列表中选择,但选择与第一个下拉列表中相同的选项。 当我在控制器中检查 null 并将属性设置为值时,该值不在下拉列表中,即。 -1,它选择更正第一个选项“<未指定>”。

当此下拉列表的模型值为 null 时,有没有办法接收选定的第一个选项?

库比克斯

I have two DropDownLists in form, both displaying list of regions. First is required, second not, stored as null in db.
When I open the page for edit and first dropdownlist is ie. Region 2, and the second is null, the first option "< not specified >" should be selected in second dropdownlist, but the same option as in first dropdownlist is selected.
When I check for null in controller and set the property to value, which is not in the dropdownlist, ie. -1, it selects corrects first option "< not specified >".

Is there a way to recieve the first option selected, when the model value for this dropdown is null ?

kubiix

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文