I am binding my drop down list with database using EF code first approach.My model class is department

  public class Department
{
    [Key]
    public int DepartmentID { get; set; }
    [Required]

    [Display(Name = "Department")]

    public string DepartmentName { get; set; }

}

I am getting all department name in ViewData

 ViewData["Departments"] = new SelectList(db.Departments,"DepartmentName");

In my view my code is this

@Html.DropDownList("Departments", "Select Department")

Thid code binding my data but not with name but their are 10 objects like MyProjectName.Models.Department

MyProjectName.Models.Department

MyProjectName.Models.Department

MyProjectName.Models.Department

MyProjectName.Models.Department ....

Need help what is going wrong in my code.

Related posts

Recent Viewed