如何在模型属性有值时设置 Html.DropDownListFor 的选定值并在属性为 null 时选择 optionLabel
如果我的模型属性为空,我希望我的下拉列表自动选择 optionLabel。如果我的财产有价值的话,也会自动选择它的价值。
我遇到的情况是,无论我的模型属性有或没有值,我的下拉列表总是选择选项标签。
@Html.DropDownListFor(m => m.SportsId, new SelectList((IEnumerable<SelectListItem>)ViewData[ViewDataKeys.SportList], "Value", "Text"),"---",null)
谢谢!
I want my dropdown to automatically select the optionLabel if my model property is null. But also automatically select the value of my property if it has value.
What is happening to me is that my dropdownlist always select the optionlabel whether my model property has or has no value.
@Html.DropDownListFor(m => m.SportsId, new SelectList((IEnumerable<SelectListItem>)ViewData[ViewDataKeys.SportList], "Value", "Text"),"---",null)
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论