I'm using Visual Studio 2013 and sql server 2008.
I created a empty ASP.NET MVC application.
I'm using the Database First Entity model.
I'm using the Employees table from the Northwind database.
So I created my entity model for my Employees table and it looks like this:
My project looks like this:
This is the code for my controller HomeController.cs
public class HomeController : Controller
// GET: /Home/
public ActionResult Index()
NorthwindEntities db = new NorthwindEntities();
ViewBag.Employees = new SelectList(db.Employees, "EmployeeID", "LastName", "FirstName");
This is the code for my view Index.cshtml
ViewBag.Title = "Home Page";
Select Employee: @Html.DropDownList("Employees", "Select Employee")
<br/> <br />
You selected: @ViewBag.LastName
When I run my page my dropdown list is filled with the correct data and it looks like this:
What I'm trying to do is bind whatever name I pick from the dropdownlist and show it in a label.
So with my code above, when I select a name from the dropdownlist nothing is showing in the label.
So for example, if I picked Davolio from the drop down list then my page should look like this:
Anyone know how I can fix my view so the selected value from the dropdownlist shows on the label?