How to create a simple dropdownlist by htmlhelper (如何靠htmlhelper建立下拉式選單)

  • 6132
  • 0
  • 2017-04-29

How to create a simple dropdownlist by htmlhelper

controller

public ActionResult Index()
        {          
            DataClasses2DataContext db =new DataClasses2DataContext (); 
            ViewData["value"] = new SelectList(db.droptest.ToList(),"ID","droptest1");
            
            return View();
        }

view

<%= Html.DropDownList("value", (IEnumerable<SelectListItem>)ViewData["value"])%>