I am new to MVC framework and cant figure out how to populate a dropdown list which binds with the database.Please help me in the view part as I want to show the Account Name in dropdown list using the following code.
Model:-
[Table("account")]
public class Accounts
{
[Key]
public int acc_id { get; set; }
public string acc_name { get; set; }
// public SelectList AccountList { get; set; }
}
AccountsContext
public class AccountsContext:DbContext
{
public DbSet<Accounts> Account { get; set; }
// public SelectList Accounts { get;set;}
}
Controller:-
public ActionResult Group()
{
Accounts ak = new Accounts();
AccountsContext accountscontext = new AccountsContext();
List<Accounts> account = accountscontext.Account.ToList();
return View(account);
}