Html.DropDownList()的用法

时间:2020-12-21 07:46:29
页面代码如下:

<%= Html.DropDownList("Category", ViewData["Categories"] as SelectList,"--请选择--",new { @class = "my-select-css-class" } )%>

Controllers代码:

public ActionResult Create() 

{
List<Category> categories = categoryService.GetAll();
ViewData["Categories"] = new SelectList(categories, "Id", "Name");
return View();
}