gpt4 book ai didi

asp.net-mvc - 如何在 ASP.NET MVC 中动态预选 html.DropDownlist 中的项目

转载 作者:行者123 更新时间:2023-12-04 22:26:30 24 4
gpt4 key购买 nike

有没有办法在页面加载或发布到服务器时预选一个项目..

这就是我现在所拥有的..

<%=Html.DropDownList("dllMonths", 
new SelectList(new List<string>() {
"", "January", "Feburary", "March", "April", "June",
"July", "August", "September", "October", "November",
"December"}),
new { onchange="this.form.submit();" })%>

最佳答案

设置 SelectList 的 SelectedValue 属性,或将其作为第二个参数传递给 SelectList 构造函数。

<% = Html.DropDownList ( "dllMonths", 
new SelectList ( new List ( )
{ "", "January", "Feburary", "March",
"April", "June", "July", "August",
"September", "October", "November",
"December" },
"April" ),
new { onchange = "this.form.submit();" }
)%>

关于asp.net-mvc - 如何在 ASP.NET MVC 中动态预选 html.DropDownlist 中的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/450669/

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