public ViewResult Index() { //Create db context object here AdventureWorksDbContext dbContext = new AdventureWorksDbContext(); //Get the value from database and then set it to ViewBag to pass it View IEnumerableitems = dbContext.Employees.Select(c => new SelectListItem { Value = c.JobTitle, Text = c.JobTitle }); ViewBag.JobTitle = items; return View(); }
@Html.DropDownList("JobTitle", "Select a Value")
沒有留言:
張貼留言