在mvc中经常会使用到下拉列表,以下以两种方式来实现,一种是以  @Html.DropDownList 扩展方法,一种是以 <select><option></option></select> 这样的 html 代码和 HashTable来实现

1.  @Html.DropDownList 扩展方法

 View 代码:

            @if (ViewData["listCategory"] != null)
            {
                @Html.DropDownList("listcategory", ViewData["listCategory"] as IEnumerable<SelectListItem>, "---请选择类型---")
            }
View Code

相关文章: