How to populate drop down with Entity Framework in mvc
I have the following table bookAssignment:
ID Group OFFICE name FKOffice FKGroup
---------------------------
1 Test1 X West 1 1
2 Test3 Y North 2 2
3 Test1 Z South 3 1
4 Test1 P South 4 1
I have around 3000 rows in this table where ID is unique and primary key. GROUP and Office has lot of repeated value.
I have another table for Office and Group
tblOffice
OfficeID OfficeName
1 X
2 Y
3 Z
4 P
tblGroup
GroupID GroupName
1 Test1
2 Test3
3 Test6
I have the following model class:
public partial class bookAssignment_new
{
public int ID { get; set; }
public Nullable Book { get; set; }
public string TechName { get; set; }
public string Office { get; set; }
public IEnumerable<SelectListItem> OfficeList { get; set; }
public IEnumerable<SelectListItem> GroupList { get; set; }
public virtual GroupName GroupName { get; set; }
public virtual OfficeName OfficeName { get; set; }
}
I want to populate two drop downs on my view with the Office and group.
Below is my controller code:
public ActionResult Index()
{
return View();
}
How can I make a Group and Office drop down in my view and populate it with Group and Office drop down values.
Thank You.