I controller-metoden har jag en lista av klasstypen "Room".
public ActionResult Index(){
List<Room> myRoomList = new List<Room>() {
new Room() { Roomname = "Horror room", Height = 5 },
new Room() { Roomname = "Death room", Height = 6 }
};
SelectList myList = new SelectList(myRoomList, "Height", "Roomname");
ViewBag.DropdownRoomList = myList;
return View(myRoomList);
}
Filen för vyn ser ut enligt följande:
@model IList<DropDownListTestProject.Models.Room>
@{
ViewBag.Title = "DropDownList test";
}
@foreach (var amodel in Model)
{
@: Height of @amodel.Roomname is @amodel.Height metres
<br />
}
<br />
@Html.DropDownList("RoomHeight", (SelectList)ViewBag.DropdownRoomList)
Inga kommentarer:
Skicka en kommentar