gpt4 book ai didi

asp.net-mvc - 将数据动态绑定(bind)到asp.net mvc中的下拉列表

转载 作者:行者123 更新时间:2023-12-04 10:06:23 26 4
gpt4 key购买 nike

如何动态绑定(bind)数据到<%Html.Dropdownlist....在 ASP.NET MVC 中?

最佳答案

只需将正确的 IEnumerable 作为类型化模型或 ViewData 传递。尝试这样的事情(在我脑海中):

<%= Html.DropDownList(string.Empty, 
"myDropDownList",
new SelectList((IEnumerable)ViewData["stuff"],
"DescriptionProperty",
"ValueProperty"))
%>

使用 MVC 中的下拉列表助手,您不会像在旧 ASP.NET 中那样真正将数据“绑定(bind)”到它。

关于asp.net-mvc - 将数据动态绑定(bind)到asp.net mvc中的下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/214998/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com