I have some trouble creating an dropdownlist correctly in MVC. I'm not sure how to link the dropdownlist with the model, and create values for it. Right now I have the following code that creates 2x dropdownlists:
<div class="form-group">
Outward route<br />
<select class="dropdown" id="Dropdown-outward">
<option>Copenhagen</option>
<option>Oslo</option>
<option>Stockholm</option>
</select>
</div>
<div class="form-group">
Return route<br />
<select class="dropdown" id="Dropdown-return">
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</select>
</div>
I used the select & option command to create values as you see in the code. I know you can use some razor syntax like.
@Html. something
but I can't seem to do it right. Have created an model (Booking) which look like this:
namespace Project.Models
{
public class Booking
{
public int ID { get; set; }
public string Departure { get; set; }
public string Return { get; set; }
public DateTime DepartureDate { get; set; }
public DateTime ReturnDate { get; set; }
public int Adults { get; set; }
public int Childrens { get; set; }
}
}
If I use the Html helper like this:
@Html.DropDownList( )
What should i write insite the braces? and how do i add values to it, so you can select, lets say the cities Oslo, Copenhagen & Stockholm?