ASP.NET MVC 4 DropdownListFor, Auffüllen mit LINQ aus DBContext?

Haben eine harte Zeit der Suche nach Antwort auf diese Frage (Google, StackOverflow und ASP.NET).

//Model
public IEnumerable<SelectListItem> State { get; set; }

//View
@Html.DropDownListFor(m => m.State, ????)

//Controller

using (var dbcontext = MyDbContext()) {

    //??
}

return View(model);

Ich bin völlig ratlos, wie zum füllen eines mvc-dropdownlistfor mit LINQ aus einem DBContext. Ich verstehe die DBContext Sache und haben ein setup. Ich bin mir nicht klar, auf so erstellen Sie eine linq-Abfrage und dann das Ergebnis (LISTE?) der DropDownListFor Helfer? Mit MS SQL und ich habe eine Tabelle Status (id, name).

InformationsquelleAutor | 2014-08-28
Schreibe einen Kommentar