如何从 MVC 中的 DropDown 中获取选定的值?我想将它分配给一个变量。
这是我的控制器动作:
public ActionResult Drop()
{
List<SelectListItem> items = new List<SelectListItem>();
items.Add(new SelectListItem { Text = "Action", Value = "0" });
items.Add(new SelectListItem { Text = "Drama", Value = "1" });
items.Add(new SelectListItem { Text = "Comedy", Value = "2" });
items.Add(new SelectListItem { Text = "Science Fiction", Value = "3" });
items.Add(new SelectListItem { Text = "Horror", Value = "4" });
items.Add(new SelectListItem { Text = "Art", Value = "5" });
ViewData["Options"] = items;
}
这是我的看法:
@Html.DropDownList("Options", ViewData["Options"] as SelectList, "--Select Item--")