Hi all
How to bind dropdownlist in ASP.NET MVC?
Here's my controller:
public ActionResult Create()
{
DB db = new DB();
var t = db.Players.ToList();
MyPlayRoundHole model = new MyPlayRoundHole();
model.MyPlayers = t;
return View("Create", model);
}
and in my view:
<tr>
<td>Player Name:</td>
<td><%= Html.DropDownList("SelectedItem", Model.MyPlayers)%></td>
</tr>
and in my Model:
namespace Golfsys.Model
{
public class MyPlayRoundHole
{
public IList<Player> MyPlayers { get; set; }
}
}