asp.net-mvc-3 – 如何在asp.net MVC剃刀中生成dropdownlist

前端之家收集整理的这篇文章主要介绍了asp.net-mvc-3 – 如何在asp.net MVC剃刀中生成dropdownlist前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在我的剃刀我正在生成这样的下拉列表.
@{
        var listItems = new List<ListItem> 
        { 
              new ListItem { Text = "Home To School",Value = "0" },new ListItem { Text = "School To Home",Value = "1" } 
        };
    }

@Html.DropDownList("Direction",new SelectList(listItems),new {onchange = "getAlldata()"})

从这里生成的HTML就是这样的

<select id="Direction" name="Direction" onchange="getAlldata()">
<option>Home To School</option>
<option>School To Home</option>
</select>

但是我想生成这样的HTML

<select id="Direction" name="Direction" onchange="getAlldata()">
<option value="0">Home To School</option>
<option value="1">School To Home</option>
</select>

我该怎么做

解决方法

像这样使用
@Html.DropDownList("Direction",new SelectList(listItems,"Value","Text"),new {onchange = "getAlldata()"})
原文链接:https://www.f2er.com/aspnet/246481.html

猜你在找的asp.Net相关文章