I am trying to create a drop down list in MVC4 derived from a database model called 'SiteTableBookings', the runtime error is:
"An exception of type 'System.NullReferenceException' occurred in App_Web_e3cawdyt.dll but was not handled in user code"
Basically the application requires a drop down list for bookings of flights, I have searched many methods on how to achieve a drop down list online and have not been able to get the application to run.
New to MVC4 and still learning any help would be much appreciated.
Model:
public partial class SiteBookingsTable
{
public int listID { get; set; }
public string departureAirport { get; set; }
public string chooseDepartureAirport { get; set; }
public IEnumerable<SiteBookingsTable> selectDeparture = new List<SiteBookingsTable>
{
new SiteBookingsTable {listID = 0, departureAirport = "London (LTN)"},
new SiteBookingsTable {listID = 1, departureAirport = "Manchester (MAN)"}
};
}
View:
<tr>
<td>@Html.LabelFor(model => model.chooseDepartureAirport)<br />
@Html.DropDownListFor(model => model.chooseDepartureAirport,
new SelectList(Model.selectDeparture, "listID", "departureAirport")) </td>
</tr>
Controller:
public ActionResult Create()
{
return View();
}