Html. DropDownLis: bind the database, html. dropdownlis
Effect:
Method 1:
View:
1 <div class = "col-md-md-4"> 2 <div class = "input-group"> 3 <span class = "input-group-addon"> department: </span> 4 @ Html. dropDownList ("f_GroupID", ViewData ["ConsumerGroup"] as SelectList, "select", new {@ class = "form-control "}) 5 </div> 6 </div>
Note: "f_GroupID" is equivalent to name = "f_GroupID". I use the KendoUI Grid, so name = "f_GroupID" is bound to the f_GroupID of the schema of kendo.
Controller:
List<Acc_Group> AG = sdt.Acc_Group.ToList(); SelectList select = new SelectList(AG, "f_GroupID", "f_GroupName"); ViewData["ConsumerGroup"] = select;
Entity:
1 public partial class Acc_Group2 {3 public int f_GroupID { get; set; }4 public string f_GroupName { get; set; }5 public int f_GroupNO { get; set; }6 public int f_ParentId { get; set; }7 }
Method 2:
View:
1 @ Html. DropDownList ("database", null, "select", new {@ class = "form-control "})
Controller:
List <Acc_Group> AG = sdt. acc_Group.ToList (); var selectItemList = new List <SelectListItem> (); {new SelectListItem () {Value = "0", Text = "select Department ", selected = true };}; var selectList = new SelectList (AG, "f_GroupID", "f_GroupName"); selectItemList. addRange (selectList); ViewBag. database = selectItemList;