I know that there are plenty of similar questions but I couldn't get it working ... I want to populate dropdown list from entity framework entity. I have following entity class:
namespace Accounting.Entity
{
[Table("Cities", Schema = "np")]
public class Cities
{
[Key]
[XmlElement("Ref")]
public System.Guid Ref { get; set; }
[XmlElement("Description")]
public string Description { get; set; }
}
}
Controller:
public class OrderController : Controller
{
public ActionResult PopulateCitiesDD()
{
var list = _repository.All<Cities>().ToList();
ViewBag.MyCities = new SelectList(list, "Ref", "Description", 0);
return View();
}
}
What should I use in the view to populate dropdown?