Html.DropDownList()是ASP.NET MVC框架中的HTML助手方法,用于生成下拉列表(DropDownList)的HTML代码。
语法:
public static MvcHtmlString DropDownList(this HtmlHelper htmlHelper, string name, IEnumerable<SelectListItem> selectList, string optionLabel, object htmlAttributes)
参数说明:
IEnumerable<SelectListItem>
,其中SelectListItem
表示下拉列表中的每个选项。示例:
@Html.DropDownList("Country", ViewBag.CountryList as SelectList)
@Html.DropDownList("Country", ViewBag.CountryList as SelectList, "Select a Country")
@Html.DropDownList("Country", ViewBag.CountryList as SelectList, new { @class = "form-control", onchange = "countryChanged()" })
ViewBag.CountryList = new SelectList(new List<string> { "USA", "Canada", "UK", "Australia" });
以上是Html.DropDownList()方法的基本用法,可以根据需要进行参数的调整和扩展。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: 关于IDENTITY_INSERT的用法介绍